Forum Discussion

Bryan_Daniels's avatar
Bryan_Daniels
Copper Contributor
Jun 15, 2023
Solved

Clear comboboxes when opening worksheet

Hi, I have a worksheet that has 21 comboboxes.  I use these to configure a part number that the user can copy to another program.  What I need to happen is that when the Worksheet is opened, the com...
  • NikolinoDE's avatar
    Jun 16, 2023

    Bryan_Daniels 

    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!

     

Resources