Tick all in a selection of checboxes

ardykav

Board Regular
Joined
Oct 18, 2015
Messages
172
Office Version
  1. 365
Platform
  1. Windows
I have 50 checkboxes in 5 sets of ten, I was looking to implement a check all function to be able to check each set of ten if needs be, so 5 new boxes each with the ability to check all in their category. I have looked in a few places and can only seem to find check all on sheet (below) or uncheck all. Would anyone have a piece of code or an addition to the below where I can just check a certain selection of checkboxes based on their names?

VBA Code:
[LIST=1]
[*]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  
[/LIST]
TIA
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi,
You could create a common code to pass Groupname & Checkbox Value to manage your requirement.
ActiveX Checkboxes have a GroupName property that you can use to achieve this but you appear to be using Forms Control checkboxes - is this correct? Also, would be helpful if you gave some examples of naming conventions for your Group Names

Dave
 
Upvote 0
Yes I am using Form Control Checkboxes, its all pretty simple in terms of naming, Group1 Group 2 etc etc
 
Upvote 0
As form control checkboxes do not have the groupname property - to use in manner required you want you will need to index each of the Group names

For example, to change value in all checkboxes in Group1 you would have a checkbox named Group1 to control them. This will call a common code that you pass checkbox Group Name & control value to.

All checkboxes in the group you would name as follows

Group1 1

Group1 2

Group1 3

Etc etc

And do this for all other groups



Place following codes in standard module



Group1 checkbox code

VBA Code:
Sub Group1_Click()
    SetGroupCheckBoxes "Group1", ActiveSheet.CheckBoxes("Group1").Value
End Sub

This checkbox passes the Group Name & Checkbox state to the common code



Common Code

VBA Code:
Sub SetGroupCheckBoxes(ByVal GroupName As String, ByVal state As Integer)
    Dim CB As CheckBox
    For Each CB In ActiveSheet.CheckBoxes
        If CB.Name Like GroupName & "*" Then CB.Value = state
    Next CB
End Sub

This code is used by each of the checkboxes that sets the Group names. Code cycles through all forms controls checkboxes on the active sheet & if the name is like as in this example “Group1” then the value is set according to the value of control checkbox.





Hopefully, this is what you wanted.


Dave
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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