Adding the changes to only one Cell

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to add any changes to E4 to F4 as a running total. I want F4 to
keep adding to itself any thing put in E4.

Thanks for any help with this.

Tray
 
Right click sheet tab>view code>insert this>
Private Sub Worksheet_Change(ByVal target As Range)
Application.EnableEvents = False
If target.Address = "$E$4" And IsNumeric(target) Then _
Range("f4").Value = Range("f4") + target
Application.EnableEvents = True
End Sub

And, if you want e4 to change when you change e4

Option Explicit
Dim oldvalue As Double

Private Sub Worksheet_Change(ByVal target As Excel.Range)
If target.Address = "$E$4" 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
 
Exactly what I needed. Thanks

Don Guillett said:
Right click sheet tab>view code>insert this>
Private Sub Worksheet_Change(ByVal target As Range)
Application.EnableEvents = False
If target.Address = "$E$4" And IsNumeric(target) Then _
Range("f4").Value = Range("f4") + target
Application.EnableEvents = True
End Sub

And, if you want e4 to change when you change e4

Option Explicit
Dim oldvalue As Double

Private Sub Worksheet_Change(ByVal target As Excel.Range)
If target.Address = "$E$4" 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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
 
Just be warned.............you will have no "paper trail" for error checking.


Gord Dibben MS Excel MVP
 
Back
Top