How to check all Check Boxes WITHIN a group

Silverjman

Board Regular
Joined
Mar 19, 2014
Messages
110
i.e. not all the check boxes on the active sheet like the following:

I would think that the <> is the problem, I've replaced "Check Box 1" with "AllCountrys" and was hoping a simple "Country*" (* = wildcard?) would pick up "Country1", "Country2", etc. or an = LEFT(), or group and name them and then .GroupName = ....("Country") but frankly I'm just too ignorant of VBA to get anywhere.

Also hopefully clicking the Select All check box would also uncheck all boxes if checked...:\ : |

Code:
Sub SelectAll_Click()
Dim CB As CheckBox
For Each CB In ActiveSheet.CheckBoxes
  If CB.Name <> ActiveSheet.CheckBoxes("Check Box 1").Name Then
    CB.Value = ActiveSheet.CheckBoxes("Check Box 1").Value
  End If
Next CB
End Sub

Sub Mixed_State()
Dim CB As CheckBox
For Each CB In ActiveSheet.CheckBoxes
  If CB.Name <> ActiveSheet.CheckBoxes("Check Box 1").Name And CB.Value <> ActiveSheet.CheckBoxes("Check Box 1").Value And ActiveSheet.CheckBoxes("Check Box 1").Value <> 2 Then
    ActiveSheet.CheckBoxes("Check Box 1").Value = 2
Exit For
   Else
     ActiveSheet.CheckBoxes("Check Box 1").Value = CB.Value
  End If
Next CB
End Sub

or

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

please thanks please
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,223,227
Messages
6,170,855
Members
452,361
Latest member
d3ad3y3

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