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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi, Gene,
this should work
Code:
OptionButton1.Enabled = Not OptionButton1.Enabled
kind regards,
Erik
 
Upvote 0

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,367
Office Version
  1. 365
Platform
  1. Windows
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

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
ADVERTISEMENT
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

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
ADVERTISEMENT
Unless I did something wrong, none of them worked. I'll have to try again.

Gene, "The Mortgage Man", Klein
 
Upvote 0

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
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

just_jon

Legend
Joined
Sep 3, 2002
Messages
10,473
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

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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,195,829
Messages
6,011,838
Members
441,650
Latest member
ceyoung75

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
Top