cummlative addition

  • Thread starter Thread starter Frank B
  • Start date Start date
F

Frank B

I would like to add two cells and have the answer over
write one of the cells. In math they call this cummlative
addition. example: 100 dollars (cell C7) will be added the
the years total of 1000 dollars (cell C10), Now the years
total is 1100 dollars in (cell C10). I would appreciate any
help -- Thanks
 
Frank,

You need VBA for this.

Add this code to the worksheet code module

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo ws_exit
If Not Intersect(Target, Range("C7")) Is Nothing Then
If IsNumeric(Target.Value) Then
Range("C10").Value = Range("C10").Value + Target.Value
End If
End If

ws_exit:
Application.EnableEvents = True

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Here is one that will do it in the SAME cell
right click on sheet tab>view code>copy/paste this>save
use 0 to start over.

Option Explicit
Dim oldvalue As Double
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$A$5" Then
On Error GoTo fixit
Application.EnableEvents = False
If Target.Value = 0 Then oldvalue = 0
Target.Value = 1 * Target.Value + oldvalue
oldvalue = Target.Value
fixit:
Application.EnableEvents = True
End If
End Sub
 
Back
Top