# Clear option buttons



## wpryan (Dec 17, 2022)

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:


```
Sub ClearCheckBoxes()

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

End Sub
```

...any help is appreciated.


----------



## wpryan (Dec 17, 2022)

wpryan said:


> 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:
> 
> 
> ```
> ...


Well I found a workaround... Since there are not so many option buttons (8), I just set the code to 
	
	
	
	
	
	



```
Range.("Dx")ClearContents
```


----------



## Domenic (Dec 17, 2022)

You can clear your option buttons as follows . . .


```
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...


```
ActiveSheet.CheckBoxes.Value = False
```

and


```
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"...


```
ThisWorkbook.Worksheets("Sheet1").CheckBoxes.Value = False
```

Hope this helps!


----------



## wpryan (Dec 17, 2022)

Domenic said:


> You can clear your option buttons as follows . . .
> 
> 
> ```
> ...


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...


----------



## Domenic (Dec 17, 2022)

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?


----------



## wpryan (Dec 18, 2022)

Domenic said:


> 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





Domenic said:


> 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.


----------

