Forum Discussion
Clear comboboxes when opening worksheet
- Jun 16, 2023
To clear multiple CheckBoxes in a worksheet and make sure they clear each time the worksheet is opened, you can use the following code:
Private Sub Workbook_Open() Dim cb As OLEObject For Each cb In ActiveSheet.OLEObjects If TypeName(cb.Object) = "CheckBox" Then cb.Object.Value = False End If Next cb End Sub
This code should be pasted into the workbook's code module. To do this, open the Visual Basic Editor (VBE) by pressing the key combination "ALT + F11". Then double-click "ThisWorkbook" in the project window and paste the code into the window.
The code uses the Workbook_Open() event, which runs automatically when the workbook is opened. This will find all checkboxes in the active worksheet and set them to the value "False" (unchecked).
Once you save the code, the checkboxes will clear each time you open the worksheet.
Example file inserted: Open the file, click all checkboxes, then close the file and open from the new one. The checkboxes will be empty.
I hope this could help you!
To clear multiple CheckBoxes in a worksheet and make sure they clear each time the worksheet is opened, you can use the following code:
Private Sub Workbook_Open()
Dim cb As OLEObject
For Each cb In ActiveSheet.OLEObjects
If TypeName(cb.Object) = "CheckBox" Then
cb.Object.Value = False
End If
Next cb
End Sub
This code should be pasted into the workbook's code module. To do this, open the Visual Basic Editor (VBE) by pressing the key combination "ALT + F11". Then double-click "ThisWorkbook" in the project window and paste the code into the window.
The code uses the Workbook_Open() event, which runs automatically when the workbook is opened. This will find all checkboxes in the active worksheet and set them to the value "False" (unchecked).
Once you save the code, the checkboxes will clear each time you open the worksheet.
Example file inserted: Open the file, click all checkboxes, then close the file and open from the new one. The checkboxes will be empty.
I hope this could help you!
- Bryan_DanielsJun 16, 2023Copper ContributorHi NicolinoDE! Thank you for your answer. Since your code was for checkboxes, I just changed the CheckBox to ComboBox and the False to Null, and it worked like a charm. I very much appreciate it!
- NikolinoDEJun 17, 2023Gold ContributorI'm glad I could help!
Checkbox designation is in German the combo box, forgot to rename it :).