ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   click buttons to do, re-click to un-do (https://www.excelbanter.com/excel-programming/293389-click-buttons-do-re-click-un-do.html)

arciduca79[_6_]

click buttons to do, re-click to un-do
 
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

--
Message posted from http://www.ExcelForum.com


Frank Kabel

click buttons to do, re-click to un-do
 
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

--
Regards
Frank Kabel
Frankfurt, Germany

Hello all,

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

how do I do this?

Could someone help me write the code?

Thanks


---
Message posted from http://www.ExcelForum.com/



Bob Phillips[_6_]

click buttons to do, re-click to un-do
 
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)

"arciduca79 " wrote in message
...
Hello all,

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

how do I do this?

Could someone help me write the code?

Thanks


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 12:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com