Hi,
I'm using the following code to decrement expenses (column C) from a total (A1).
This works great with one small problem. If I change any value in column C, say from $100 to $50, it deducts both values from A1 instead of updating the value.
Example:
A1 is $500
C5 is changed from $100 to $50. A1 should read $450, instead it's deducting both and reading $350 even though I replaced the original value.
thx
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("C3:C20")) Is Nothing Then
Application.EnableEvents = False
If Target.Value = "" Then
Application.Undo
Range("A1").Value = Range("A1").Value + Target.Value
Target.ClearContents
Else
Range("A1").Value = Range("A1").Value - Target.Value
End If
Application.EnableEvents = True
End If
End Sub
I'm using the following code to decrement expenses (column C) from a total (A1).
This works great with one small problem. If I change any value in column C, say from $100 to $50, it deducts both values from A1 instead of updating the value.
Example:
A1 is $500
C5 is changed from $100 to $50. A1 should read $450, instead it's deducting both and reading $350 even though I replaced the original value.
thx
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("C3:C20")) Is Nothing Then
Application.EnableEvents = False
If Target.Value = "" Then
Application.Undo
Range("A1").Value = Range("A1").Value + Target.Value
Target.ClearContents
Else
Range("A1").Value = Range("A1").Value - Target.Value
End If
Application.EnableEvents = True
End If
End Sub