Is there any way to check whether an option button has been checked?

samerickson89

New Member
Joined
Jun 13, 2019
Messages
38
I'm trying to create a form where, if certain fields are blank, it prevents the user from printing I got most of the code to work, but I can't manage to figure out how to check whether an option button has been selected. A lot of resources I've found say to use something along the lines of

Code:
If OptionButton1.Value = True Then
     MsgBox "checked"
Else
     MsgBox "not checked"
End If

But that doesn't work at all. I've also tried

Code:
If OptionButton1 = True Then...

But that gives me "not checked" whether the radio button is selected or not. Then just for the heck of it I tried

Code:
If OptionButton1 = False Then...

Which gives me "checked" whether the radio button is selected or not. I'm at a loss here... is there a simple way to verify that a radio button has been selected? I'm using the option button under "form controls" not "ActiveX controls"
 
It looks like you have an option button from the ActiveX Controls. The OLEObject is the container holding the option button object, so you'll need to refer to the Object property of the OLEObject, as I did in Post #6 . So it should be...

Code:
[COLOR=#574123]If Worksheets("Sheet1").OLEObjects("OptionButton1").[/COLOR][COLOR=#ff0000]Object[/COLOR][COLOR=#574123].Value = False And _[/COLOR]

Does this help?

That was it! So it looks like I needed to account for the fact that I was using ActiveX option buttons, and once I did that I was just forgetting the ".Object" portion of the code. Thanks!
 
Upvote 0

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.

Forum statistics

Threads
1,214,591
Messages
6,120,426
Members
448,961
Latest member
nzskater

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