ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Toggle command buttons (https://www.excelbanter.com/excel-programming/332650-toggle-command-buttons.html)

geb

Toggle command buttons
 
I have an "Analysis" and a "Clear" button.
At first I only want the "Analysis" button to be active
and the "Clear" button disabled.
After the "Analysis" button is clicked I want the reverse, and
so on (toggle).
I didn't see any code window for the controls.
How can I code this?



Bob Phillips[_7_]

Toggle command buttons
 
Where did you get the controls from the Forms toolbar or the control
toolbox.

--
HTH

Bob Phillips

"GEB" wrote in message
...
I have an "Analysis" and a "Clear" button.
At first I only want the "Analysis" button to be active
and the "Clear" button disabled.
After the "Analysis" button is clicked I want the reverse, and
so on (toggle).
I didn't see any code window for the controls.
How can I code this?





bhofsetz[_82_]

Toggle command buttons
 

If the buttons are from the control toolbox then the code would be
placed on the code window behind the worksheet on which the buttons
reside.

You can get the buttons to 'toggle' with the following code


Code:
--------------------
Private Sub CommandButton1_Click()
CommandButton1.Enabled = False
CommandButton2.Enabled = True
'Your code here
End Sub

Private Sub CommandButton2_Click()
CommandButton2.Enabled = False
CommandButton1.Enabled = True
'Your code here
End Sub
--------------------


You could also use a single button and have it's caption change with
each click and then the action taken depend on the value of the
caption.


Code:
--------------------
Private Sub CommandButton1_Click()
If CommandButton1.Caption = "Analysis" Then
CommandButton1.Caption = "Clear"
'your analysis code here
Exit Sub
End If
If CommandButton1.Caption = "Clear" Then
CommandButton1.Caption = "Analysis"
'your clear code here
Exit Sub
End If
End Sub
--------------------


HTH


--
bhofsetz
------------------------------------------------------------------------
bhofsetz's Profile: http://www.excelforum.com/member.php...o&userid=18807
View this thread: http://www.excelforum.com/showthread...hreadid=381663


geb

Toggle command buttons
 
From the Forms toolbar.

"Bob Phillips" wrote:

Where did you get the controls from the Forms toolbar or the control
toolbox.

--
HTH

Bob Phillips

"GEB" wrote in message
...
I have an "Analysis" and a "Clear" button.
At first I only want the "Analysis" button to be active
and the "Clear" button disabled.
After the "Analysis" button is clicked I want the reverse, and
so on (toggle).
I didn't see any code window for the controls.
How can I code this?






geb

Toggle command buttons
 
OK, I replaced the forms buttons with ones from the control toolbox
and was able to code them.

Thanks for your help.

"GEB" wrote:

From the Forms toolbar.

"Bob Phillips" wrote:

Where did you get the controls from the Forms toolbar or the control
toolbox.

--
HTH

Bob Phillips

"GEB" wrote in message
...
I have an "Analysis" and a "Clear" button.
At first I only want the "Analysis" button to be active
and the "Clear" button disabled.
After the "Analysis" button is clicked I want the reverse, and
so on (toggle).
I didn't see any code window for the controls.
How can I code this?







All times are GMT +1. The time now is 05:46 AM.

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