Need Automated Laziness

medic704

New Member
Joined
Dec 20, 2012
Messages
1
Ok, so I've got 14 toggle buttons on a worksheet that ultimately could grow to be a hundred of them. I want the buttons to have no caption when idle and I want them to say "OFF" when depressed. I know how to write a sub for each button to do so.

Private Sub ToggleButton1_Click()
If ToggleButton1.Caption = "OFF" Then
ToggleButton1.Caption = ""
Else
ToggleButton1.Caption = "OFF"
End If
End Sub

However, considering the end of the world is supposed to be tomorrow and I don't have that much time, I would like to know if there is a sub that I could write to control all of the buttons at once?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi and welcome to the forum.
Here you go:

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] CommandButton1_Click()
   ResetToggleButtons
[color=darkblue]End[/color] [color=darkblue]Sub[/color]




[color=darkblue]Private[/color] [color=darkblue]Sub[/color] ResetToggleButtons()
   [color=darkblue]Dim[/color] ctrl [color=darkblue]As[/color] Control
   
   [color=darkblue]For[/color] [color=darkblue]Each[/color] ctrl [color=darkblue]In[/color] Me.Controls
      [color=darkblue]If[/color] TypeName(ctrl) = "ToggleButton" [color=darkblue]Then[/color]
         [color=darkblue]If[/color] ctrl.Caption = "OFF" [color=darkblue]Then[/color]
            ctrl.Caption = ""
         [color=darkblue]Else[/color]
            ctrl.Caption = "OFF"
         [color=darkblue]End[/color] [color=darkblue]If[/color]
      [color=darkblue]End[/color] [color=darkblue]If[/color]
   [color=darkblue]Next[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]

Have a nice End of the World.
Bertie
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top