Excel adding cells dynamically (SOLVED)

Singh 0 Reputation points
2024-10-28T19:12:37.53+00:00

How can two cells be added together in Excel such that the result is retained in the second cell, while the first cell resets to 0 after the operation?

Specifically, when Cell 1 is added to Cell 2, I want Cell 2's value to equal the sum of the original values, and then Cell 1 should become 0.

Microsoft 365 and Office Excel For business Windows
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Singh 0 Reputation points
    2024-10-28T19:47:18.47+00:00

    I solved it, the code needed was

    Sub AddAndResetCells()
    Dim cell1 As Range
    Dim cell2 As Range

    ' Change the addresses to your specific cells
    Set cell1 = Range("A1")
    Set cell2 = Range("A2")

    cell2.Value = cell1.Value + cell2.Value
    cell1.Value = 0
    End Sub

    0 comments No comments

  2. Emi Zhang-MSFT 30,046 Reputation points Microsoft External Staff
    2024-10-29T00:28:04.4966667+00:00

    Hi,

    Thanks for sharing the solution here. :D

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.