VBA Select/Unselect Checkboxes

Kappy

Board Regular
Joined
Jun 26, 2009
Messages
58
I have a simple code to Select/Unselect all the checkboxes (Form Control) on the Active sheet.

The code works in that the values of the target cell change correctly from TRUE to FALSE and visa versa..

BUT, the checkboxes themselves don't show the change (i.e., the check marks in the boxes don't appear/disappear) until I run a second macro (literally any other macro) afterward.

My code is below, thank you for your help!



Sub Select_All()
ActiveSheet.CheckBoxes.Value = True
ActiveSheet.Calculate
End Sub

Sub UnSelect_All()
ActiveSheet.CheckBoxes.Value = False
ActiveSheet.Calculate
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try

Code:
Sub CheckAllBoxes()
    SetAllFormsCheckboxes True
End Sub
Sub UnCheckAllBoxes()
    SetAllFormsCheckboxes False
End Sub
Sub toggleAllBoxes()
    SetAllFormsCheckboxes False, True
End Sub

Sub SetAllFormsCheckboxes(ByVal newValue As Boolean, Optional Toggle As Boolean)
    Dim oneShape As Object
    For Each oneShape In ActiveSheet.Shapes
        With oneShape
            If .Type = msoFormControl Then
                If .FormControlType = xlCheckBox Then
                    If Toggle Then newValue = Not (.ControlFormat.Value = xlOn)
                    .ControlFormat.Value = IIf(newValue, xlOn, xlOff)
                End If
            End If
        End With
    Next oneShape
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,182
Messages
6,129,364
Members
449,506
Latest member
nomvula

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