How to force a user to select an option button?

Rainmanne

Board Regular
Joined
Mar 10, 2016
Messages
132
Office Version
  1. 2013
Platform
  1. Windows
I've got a model with a code that should depend on the selection of one of two option buttons. When a user opens the model, the both option buttons are unselected. I need to make sure that the user selects one of them before the main code is run. So if nothing is selected, then it should display a message box saying something like "Please select an option" and stop the rest of the code from executing.

I guess it should be an IF statement using OptionButton.Value = False as a condition, but I cannot figure out how to do it. It should be something like

VBA Code:
Sub optionbuttonselect()
If ActiveSheet.OptionButtons("Option Button 2").Value = False Then
If ActiveSheet.OptionButtons("Option Button 4").Value = False Then
MsgBox "Check the options"
    End If
    End If
End Sub

But it obviously does not work.
 
Thanks a lot. I just cannot figure out where to put End If if it's needed.

No "EndIfs needed in my codes as the are one liners & code should, assuming that you have following my direction & not made any changes, do what you want.

If getting compile error suggest you publish your main code

Dave
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
No "EndIfs needed in my codes as the are one liners & code should, assuming that you have following my direction & not made any changes, do what you want.

If getting compile error suggest you publish your main code

Dave
Sorry, of course. It was a different IF structure. My mistake. Thanks a lot for your help, it works perfectly!
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,239
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