My code is from a website online. All that it is supposed to do is add 1 to the value of E2 every time the user changes A2. I wanted it to reset E2 to zero every time the user clicked a button.
VBA Code:
Dim Cont As Integer
'Integer means no decimals
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rnge As Range, Cll As Range
On Error Resume Next
If Target = Range("A2") Then
Cont = Cont + 1
'If the user clicked this cell then the variable "Cont" will change to Cont+1
Range("E2").Value = Cont
'The cell E2 needs updating to the new value
End If
'EXPERIMENTAL: If Button is clicked End If statement & clear E2
Application.EnableEvents = False
Set Rnge = Application.Intersect(Target.Dependents, Me.Range("A2"))
If Not Rnge Is Nothing Then
Cont = Cont + 1
Range("E2").Value = Cont
End If
Application.EnableEvents = True
End Sub