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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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