click buttons to do, re-click to un-do

  • Thread starter Thread starter arciduca79
  • Start date Start date
A

arciduca79

Hello all,

I would like to add a button in a spreadsheet and have it do a
operation when cliked and undo the same operation when clicked again.

how do I do this?

Could someone help me write the code?

Thank
 
Hi
one way: Declare a static variable. e.g.

----
Private Sub CommandButton1_Click()
Static status As Boolean
If status Then
' your code for undoing something
CommandButton1.Caption = "Do something"
status = False
Else
' your code for doing something
CommandButton1.Caption = "Undo something"
status = True
End If

End Sub
 
Add a checkbox instead of a button and test its value for True/False

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top