Unable to return Option Button Value

bigel

New Member
Joined
Jul 27, 2011
Messages
2
When I try to run the following code I get a Variable Not Defined error message.

Select Case OptionButton1.Value
Case True
Sheet1.Cells(1, 1) = "YES"
Case False
Sheet1.Cells(1, 1) = "NO"
End Select

I have tried creating the option buttons both from the forms toolbar and from the controls toolbar and I can't get either to work. Am I missing a reference or something?

Thanks in advance for any help you can provide. :biggrin:
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Where is the code? A sheet module? A standard code module, the Thisworkbook module perhaps?, or maybe elsewhere?
 
Upvote 0
I think its more that you have:

Code:
Case True
Code:
Case False

I think the compiler is assuming these are variables and currently have no value set. Try changing them to "True" and "False" (with the quotations)
 
Upvote 0
Where is the code? A sheet module? A standard code module, the Thisworkbook module perhaps?, or maybe elsewhere?
Also, where is the button? On a form, a sheet?
(And you probably have Option Explicit at the top of the module (you shouldn't necessarily remove it, it probably won't help to do so))
 
Upvote 0
Found the fix - I just needed to add ActiveSheet in front of the optionbutton1.value part and it works fine now.

Thanks

Select Case ActiveSheet.OptionButton1.Value
Case True
MsgBox ActiveSheet.OptionButton1.Value
Case False
MsgBox "NO"
End Select
 
Upvote 0

Forum statistics

Threads
1,224,563
Messages
6,179,527
Members
452,923
Latest member
JackiG

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