Unselect All CheckBoxes From Excel Workbook with VBA Macro
Asked Answered
U

2

8

I have a workbook with over 100 checkboxes.

They are form control checkboxes

I would like to un-select them all at once

that is set them to false.

 Sub clearcheck()
 ActiveSheet.CheckBoxes.Value = False
 End Sub

This works for the active sheet. I would like this code to be for the whole workbook

I have tried looking for the code and messing about with clearing the checkboxes but am none the wiser.

I would really appreciate if some one could guide me

thank you

Ursine answered 21/9, 2013 at 0:28 Comment(2)
What kind of checkboxes are those? Form Control or ActiveX Control?Durrett
Well, I GUESS they are ActiveX. In that case Gary's answer will do the job :)Durrett
S
16

If you have OLEObject-style (ActiveX) checkboxes, then:

Sub terranian()
    Dim o As Object
    For Each o In ActiveSheet.OLEObjects
        If InStr(1, o.Name, "CheckBox") > 0 Then
            o.Object.Value = False
        End If
    Next
End Sub

EDIT1:

If they are forms checkboxes , then the following will work:

Sub clearcheck()
    Dim sh As Worksheet
    For Each sh In Sheets
        On Error Resume Next
            sh.CheckBoxes.Value = False
        On Error GoTo 0
    Next sh
End Sub
Shading answered 21/9, 2013 at 1:43 Comment(3)
Hi Gary, many thanks for your answer, the checkboxes are form control and not active x, will this code still work?Ursine
Hi Gary, This works perfectly fine for active x checkboxes in the active sheet. I am looking for one macro when clicked will unselect all the form control checkboxes in the workbook, please adviseUrsine
Gary's Student You are my hero!!! Thank you so much Sir , you saved me at least a couple of hours of pulling my hair out, Kudos to you and so very pleased, well done and stack overflow should have more people like you!! :) : ) : )Ursine
L
0

The selected answer is perfect, but I needed the ability to clear the active sheet OR all check-boxes via buttons for form checkboxes. Putting both sub routines inside of one "Module" worked for me. Then I created a button for each action, and mapped to the individual sub-routines.

'Uncheck all checkboxes in entire excel workbook
Sub uncheck_all()
    Dim sh As Worksheet
    For Each sh In Sheets
        On Error Resume Next
            sh.Checkboxes.Value = False
        On Error GoTo 0
    Next sh
End Sub

'Uncheck all checkboxes in active sheet
Sub uncheck_active_sheet()
    ActiveSheet.Checkboxes.Value = False
End Sub
Leveret answered 16/4, 2020 at 15:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.