How to toggle?

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
I have the following two functions. One to turn off 6 option buttons and one to turn them on. Is there any way to just have one function which toggles them?

Private Sub opTurnOffPlayerSide()
OptionButton1.Enabled = False
OptionButton2.Enabled = False
OptionButton3.Enabled = False
OptionButton4.Enabled = False
OptionButton5.Enabled = False
OptionButton6.Enabled = False
End Sub

Private Sub opTurnOnPlayerSide()
OptionButton1.Enabled = True
OptionButton2.Enabled = True
OptionButton3.Enabled = True
OptionButton4.Enabled = True
OptionButton5.Enabled = True
OptionButton6.Enabled = True
End Sub

Gene, "The Mortgage Man", Klein
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi, Gene,
this should work
Code:
OptionButton1.Enabled = Not OptionButton1.Enabled
kind regards,
Erik
 
Upvote 0
Gene

Does this (untested) code work?
Code:
Private Sub opTurnOffPlayerSide() 
Dim I As Long
For I =1 to 6
     Me.Controls("OptionButton" & i).Enabled =Not Me.Controls("OptionButton" & i).Enabled
Next I
End Sub
 
Upvote 0
hmmm!
just_jon, same reply but it doens't seem to work
this works for me
Code:
OptionButton1.Enabled = Not OptionButton1.Enabled = True
 
Upvote 0
Unless I did something wrong, none of them worked. I'll have to try again.

Gene, "The Mortgage Man", Klein
 
Upvote 0
Ok Norie's is certainly working. It just was happening so fast (turning off, the computer moving and turning back on) that I didn't realize it. (It is kinda of like light: light moves so fast that it took some really smart people to realize that it moves at all) I didn't double check all the others. But thanks all three of you

Gene, "The Mortgage Man", Klein
 
Upvote 0
erik.van.geit said:
hmmm!
just_jon, same reply but it doens't seem to work
this works for me
Code:
OptionButton1.Enabled = Not OptionButton1.Enabled = True

Huh. Worked for me.
 
Upvote 0
just_jon,
so this worked for you ?
OptionButton1.Enabled = Not OptionButton1.Enabled

well, now for me too :confused: :biggrin:

mistery ...?..!
thanks for reply anyway,
best regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

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