ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Toggle Button (https://www.excelbanter.com/excel-programming/299804-toggle-button.html)

Keri[_2_]

Toggle Button
 
I have a toggle button that when clicked ON I want to run
one code and when clicked OFF I want to run a different
code. Is this possible?? Please help me out.

--Keri

Bob Phillips[_6_]

Toggle Button
 
If it is a toolbar button, you can set and check its State property.

If it is a commandbutton, then you could use a global variable and set
/unset that,

Dim fStatus As Boolean

Private Sub CommandButton1_Click()

If fStatus Then
'do one thing
Else
'do an other
End If

fStatus = Not fStatus

End Sub

--

HTH

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

"Keri" wrote in message
...
I have a toggle button that when clicked ON I want to run
one code and when clicked OFF I want to run a different
code. Is this possible?? Please help me out.

--Keri




Tom Ogilvy

Toggle Button
 
Bob told you how to do it with a commandbutton and a forms button.

If it is a toggle button as you imply

Private Sub ToggleButton1_Click()
if ToggleButton1.Value = True then ' depressed
macro1
else
macro2
End if
End Sub

--
Regards,
Tom Ogilvy

"Keri" wrote in message
...
I have a toggle button that when clicked ON I want to run
one code and when clicked OFF I want to run a different
code. Is this possible?? Please help me out.

--Keri





All times are GMT +1. The time now is 01:24 PM.

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