Link to home
Start Free TrialLog in
Avatar of ca1358
ca1358

asked on

Clear a Static Event

I am using Excel VBA

Is there any way to clear the static event when you click the Refresh Button?

Any help would greatly be appreciated!

Private Sub Commandbutton28_Click()
Static intCounter As Integer
intCounter = intCounter + 1
MsgBox "Clicked" & " " & intCounter
End Sub

Private Sub cbRefresh_Click()


End Sub
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

No, because the Static variable is local to the sub in which it is defined.

You would have to make intCounter a module level variable and simply reset it:

Dim intCounter As Integer

Private Sub Commandbutton28_Click()
  intCounter = intCounter + 1
  MsgBox "Clicked" & " " & intCounter
End Sub

Private Sub cbRefresh_Click()
    intCounter = 0
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ca1358
ca1358

ASKER

Thank you!