makro that sums every new number entered in cell

  • Thread starter Thread starter Mario
  • Start date Start date
M

Mario

my problem:
i want to enter a number in A1
and everytime when u enter a number in a1 the macro adds the new number to
the old one BUT in the end there sould be the hole thing in the cell as
code...


A1 A1 - 0
input "14" in A1 A1 - 14
input "10" in A1 A1 - 24
input "-2" in A1 A1 - 22

at the end A1 = "14 + 10 - 2 " = 22

so that u can controll what is typed in

kind regards
mario
 
This may not be the most elegant solution but it works:


Public oldvalue
Public Done As Boolean

Private Sub Worksheet_Change(ByVal Target As Range)
If Done Then Exit Sub
If oldvalue = Target.Value Then Exit Sub
If Target.Address = "$A$1" Then
Done = True
[A1] = oldvalue + Target.Value
End If

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Address <> "$A$1" Then Exit Sub
oldvalue = Target.Value
Done = False
End Sub
 
Back
Top