VBA - Determining what radio button is selected

HedgePig

Board Regular
Joined
Jun 27, 2002
Messages
146
Hello

I have a spreadsheet which has a lot of controls in it option buttons and checkboxes.
In VBA, how do I determine what the currently selected button is? I'm wanting to do something like

Activecontrol.Value = FALSE

Basically, I'm wanting to allow the user to reset an option button to "unselected". This can't be done directly by because once you've selected an option button you can only "unselect" it by choosing another option button in the same group. I want the user to be able to clear all selections in the group. I aim to achieve this by having a command button which when pressed would unselect the previously selected option button setting its value to "FALSE".

I realise I may have a problem here because by clicking the command button, the previously selected option button will no longer be zero. I can get around this by running the macro using shortcut keys. Or maybe there is also a way of easily what the last-but-one selected button is?

Any suggestions?

Regards
HedgePig
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Assign code to button .... resets all Optionbuttons
Code:
Dim sh As Shape

For Each sh In ActiveSheet.Shapes
    If sh.FormControlType = xlOptionButton Then
        sh.OLEFormat.Object.Value = False
    End If
Next
 
Upvote 0
Hello Ivan

Thanks for your reply - sorry I missed it earlier!

What you are suggesting will reset ALL the options buttons. I'm simply wanting to reset whatever option button is currently selected. But I don't know how to identify what control is currently selected.

Regards
HedgePig
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,957
Latest member
Hat4Life

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