select all check boxes in a column

mrbil

New Member
Joined
Sep 22, 2014
Messages
6
I am trying to write a macro to select all (or de-select all) check boxes in a column. I found help on selecting "all" check boxes on active sheet but I need to limit it to just a particular column. I have Excel 2013.
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,406
Are the CheckBoxes Form controls or ActiveX controls? If they're Form controls, try...

Code:
[COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit
[/COLOR]
[COLOR=darkblue]Sub[/COLOR] SelectCheckBoxes()

    [COLOR=darkblue]Dim[/COLOR] oChBx       [COLOR=darkblue]As[/COLOR] CheckBox
    [COLOR=darkblue]Dim[/COLOR] sCol        [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    
    sCol = "C" [COLOR=green]'change the column as desired[/COLOR]
    
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] oChBx [COLOR=darkblue]In[/COLOR] ActiveSheet.CheckBoxes
        [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] Intersect(Range(oChBx.TopLeftCell, oChBx.BottomRightCell), Columns(sCol)) [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
            oChBx.Value = [COLOR=darkblue]True[/COLOR]
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]Next[/COLOR] oChBx
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Hope this helps!
 

mrbil

New Member
Joined
Sep 22, 2014
Messages
6
Thank for replying Domenic. That worked very well for selecting the column of check boxes. It is a Form control. What do I add to this so that unchecking the top box deselects all others in that column?
 

mrbil

New Member
Joined
Sep 22, 2014
Messages
6
As it is right now, i have to uncheck each box separately and when I try to uncheck the top box it just checks all others in that column again
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,406

ADVERTISEMENT

Try assigning the following macro to the top CheckBox...

Code:
[COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit
[/COLOR]
[COLOR=darkblue]Sub[/COLOR] ToggleCheckBoxes()

    [COLOR=darkblue]Dim[/COLOR] oChBx       [COLOR=darkblue]As[/COLOR] CheckBox
    [COLOR=darkblue]Dim[/COLOR] sCol        [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    
    sCol = "C" [COLOR=green]'change the column as desired[/COLOR]
    
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] oChBx [COLOR=darkblue]In[/COLOR] ActiveSheet.CheckBoxes
        [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] Intersect(Range(oChBx.TopLeftCell, oChBx.BottomRightCell), Columns(sCol)) [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
            [COLOR=darkblue]If[/COLOR] oChBx.Name <> Application.Caller [COLOR=darkblue]Then[/COLOR]
                oChBx.Value = IIf(oChBx.Value = 1, -4146, 1)
            [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]Next[/COLOR] oChBx
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Hope this helps!
 
Last edited:

mrbil

New Member
Joined
Sep 22, 2014
Messages
6
Excellent Domenic! Like a charm. Now, to take it a step further, I have an identical column beside the original column with the same check box scenario, but it is solely independant. I have tried to tweak what you supplied but to no avail. The second column seems to be tied to the first, so I guess I'm not tweaking it correctly.
 

mrbil

New Member
Joined
Sep 22, 2014
Messages
6

ADVERTISEMENT

sorry, "I guess I"m tweaking it INcorrectly"
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,406
Try assigning the following macro to the top checkboxes in each column...

Code:
[COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit
[/COLOR]
[COLOR=darkblue]Sub[/COLOR] Select_Unselect_All_CheckBoxes()

    [COLOR=darkblue]Dim[/COLOR] oTopChBx    [COLOR=darkblue]As[/COLOR] CheckBox
    [COLOR=darkblue]Dim[/COLOR] oChBx       [COLOR=darkblue]As[/COLOR] CheckBox
    [COLOR=darkblue]Dim[/COLOR] rCol        [COLOR=darkblue]As[/COLOR] Range
    
    [COLOR=darkblue]Set[/COLOR] oTopChBx = ActiveSheet.CheckBoxes(Application.Caller)
    
    [COLOR=darkblue]Set[/COLOR] rCol = oTopChBx.TopLeftCell.EntireColumn
    
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] oChBx [COLOR=darkblue]In[/COLOR] ActiveSheet.CheckBoxes
        [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] Intersect(oChBx.TopLeftCell, rCol) [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
            [COLOR=darkblue]If[/COLOR] oChBx.Name <> Application.Caller [COLOR=darkblue]Then[/COLOR]
                oChBx.Value = oTopChBx.Value
            [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]Next[/COLOR] oChBx
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Make sure that all checkboxes lie within their respective column border.

Hope this helps!
 

Watch MrExcel Video

Forum statistics

Threads
1,122,327
Messages
5,595,526
Members
413,996
Latest member
mabelO

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
Top