Clear option buttons

wpryan

Well-known Member
Joined
May 26, 2009
Messages
534
Office Version
  1. 365
Platform
  1. Windows
Hi All, I have a worksheet that contains some checkboxes and some option buttons. I have code to deselect the checkboxes, and am looking for something similar for the option buttons. The code I have is:

VBA Code:
Sub ClearCheckBoxes()

    Dim chkBox As CheckBox
    For Each chkBox In ActiveSheet.CheckBoxes
            chkBox.Value = xlOff
    Next chkBox

End Sub

...any help is appreciated.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi All, I have a worksheet that contains some checkboxes and some option buttons. I have code to deselect the checkboxes, and am looking for something similar for the option buttons. The code I have is:

VBA Code:
Sub ClearCheckBoxes()

    Dim chkBox As CheckBox
    For Each chkBox In ActiveSheet.CheckBoxes
            chkBox.Value = xlOff
    Next chkBox

End Sub

...any help is appreciated.
Well I found a workaround... Since there are not so many option buttons (8), I just set the code to
VBA Code:
Range.("Dx")ClearContents
 
Upvote 0
You can clear your option buttons as follows . . .

VBA Code:
Sub ClearOptionButtons()

    Dim optBtn As OptionButton
    For Each optBtn In ActiveSheet.OptionButtons
        optBtn.Value = False
    Next optBtn

End Sub

However, since you are clear all checkboxes and all optionbuttons, you can easily do it this way...

VBA Code:
ActiveSheet.CheckBoxes.Value = False

and

VBA Code:
ActiveSheet.OptionButtons.Value = False

By the way, I suggest you fully qualify your reference. So, for example, assuming that the workbook containing running the code contains the sheet that contains your form controls, and that the sheet is named "Sheet1"...

VBA Code:
ThisWorkbook.Worksheets("Sheet1").CheckBoxes.Value = False

Hope this helps!
 
Upvote 0
Solution
You can clear your option buttons as follows . . .

VBA Code:
Sub ClearOptionButtons()

    Dim optBtn As OptionButton
    For Each optBtn In ActiveSheet.OptionButtons
        optBtn.Value = False
    Next optBtn

End Sub

However, since you are clear all checkboxes and all optionbuttons, you can easily do it this way...

VBA Code:
ActiveSheet.CheckBoxes.Value = False

and

VBA Code:
ActiveSheet.OptionButtons.Value = False

By the way, I suggest you fully qualify your reference. So, for example, assuming that the workbook containing running the code contains the sheet that contains your form controls, and that the sheet is named "Sheet1"...

VBA Code:
ThisWorkbook.Worksheets("Sheet1").CheckBoxes.Value = False

Hope this helps!
Thanks for your reply. The code for the checkboxes is much simpler, I appreciate it.

For the option buttons, there seems to be a problem... They are not reset. I put them into Group Boxes and renamed themto something more meaningful for me (some other code hides rows that have the associated objects, so I will need to make them hidden or visible as needed. Therefore I renamed them to something more meaningful - example: optPM_R11_1). Because the code wasn't working I put another option button, and the code worked with the newly added one, but not the others. I then renamed a couple of the existing ones to "Option Button PM_R11_1 (to use the previously mentioned example). It's still not working, I don't know if it's because the option buttons are in the Group Boxes, or for some other reason...
 
Upvote 0
Actually, it doesn't matter whether or not the option buttons are in a Group Box. Are you sure that they are in fact form controls and not ActiveX controls?
 
Upvote 0
Actually, it doesn't matter whether or not the option buttons are in a Group Box. Are you sure that they are in fact form controls and not

Actually, it doesn't matter whether or not the option buttons are in a Group Box. Are you sure that they are in fact form controls and not ActiveX controls?
Thanks again for your help. The controls are indeed Form controls. The proble was that I grouped the Group Box together with both Option buttons (easier for copy/paste). Ungrouping them fixed the problem.
 
Upvote 0

Forum statistics

Threads
1,215,698
Messages
6,126,270
Members
449,308
Latest member
VerifiedBleachersAttendee

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