I am creating a model in Excel in which a cell computes the sum of two cells and keeps adding to the value every time the two cells on which it is dependent change values. For example,
If,
A + B = C
Then,
Instance 1: -> 5 + 5 = 10
Instance 2: -> 4 + 3 = 17
Instance 3: -> 2 + 3 = 22
and so on...
I believe this can be achieved through a VB script.
you only need to put the following code in the worksheet code pane:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Range("A1:A2"), Target) Is Nothing Then Exit Sub
Range("B1") = Range("B1") + WorksheetFunction.sum(Range("A1:A2"))
End Sub
of course you have to change:
all "A1:A2" occurrences to your actual cells to sum address
all "B1" occurrences to your actual cell holding the running sum address
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With