Using a button to select all check boxes (with a wrinkle)

philryan29

New Member
Joined
Jan 22, 2016
Messages
4
I have seen a few tutorials that show how to select all check boxes by selecting a single check box, but I am trying to perform this action by clicking a button and am struggling to adapt the instructions. Also, I would like to perform this action only on check boxes where the related row is not blank.

Example, A1:A3 each contain a check box. B1 and B2 have values, but B3 is blank. I would like to be able to click a button and select only A1 and A2. In actual use, I would likely have 200 rows, each with a check box, and anywhere from 0-199 of the rows may be blank any given time the sheet is loaded.

Any help would be much appreciated!:biggrin:
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Are the checkboxes form controls? Or are they ActiveX controls? If they're the former, try...

Code:
[color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Sub[/color] SelectCheckBoxes()

    [color=darkblue]Dim[/color] ws [color=darkblue]As[/color] Worksheet
    [color=darkblue]Dim[/color] oChBx [color=darkblue]As[/color] CheckBox
    
    [color=darkblue]Set[/color] ws = Worksheets("Sheet1") [color=green]'change the sheet name accordingly[/color]
    
    [color=darkblue]For[/color] [color=darkblue]Each[/color] oChBx [color=darkblue]In[/color] ws.CheckBoxes
        [color=darkblue]With[/color] oChBx
            [color=darkblue]If[/color] [color=darkblue]Not[/color] Intersect(ws.Columns("A"), .TopLeftCell) [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
                [color=darkblue]If[/color] Len(.TopLeftCell.Offset(, 1)) > 0 [color=darkblue]Then[/color]
                    .Value = [color=darkblue]True[/color]
                [color=darkblue]Else[/color]
                    .Value = [color=darkblue]False[/color]
                [color=darkblue]End[/color] [color=darkblue]If[/color]
            [color=darkblue]End[/color] [color=darkblue]If[/color]
            
        [color=darkblue]End[/color] [color=darkblue]With[/color]
    [color=darkblue]Next[/color] oChBx
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,569
Members
449,038
Latest member
Guest1337

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