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.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
20,240
Office Version
  1. 365
Platform
  1. Windows
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
20,240
Office Version
  1. 365
Platform
  1. Windows

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
20,240
Office Version
  1. 365
Platform
  1. Windows
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!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,668
Messages
5,838,680
Members
430,563
Latest member
Raeyven

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