[VBA] loop through all check box buttons on a sheet

smallxyz

Active Member
Joined
Jul 27, 2015
Messages
393
Office Version
  1. 2021
Platform
  1. Windows
I have 10 checkboxes on a sheet.

Their names:

ck_1
ck_2
ck_3
ck_4
ck_5

ck_10



Instead of setting

ck_1.Value = False one-by-one

Is there a way to loop through all these check box buttons which have specific names?

Thanks!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
If your checkboxes are Form controls, and you don't have any other checkboxes on your worksheet, you can set them all to False with a single line...

Code:
Worksheets("Sheet1").CheckBoxes.Value = False

If your checkboxes are Form controls, and you need to loop through your checkboxes, try...

Code:
    Dim i As Long
    
    For i = 1 To 10
        Worksheets("Sheet1").CheckBoxes("ck_" & i).Value = False
    Next i

If your checkboxes are ActiveX controls, try...

Code:
    Dim i As Long
    
    For i = 1 To 10
        Worksheets("Sheet1").OLEObjects("ck_" & i).Object = False
    Next i

Change the sheet name, accordingly.

Hope this helps!
 
Upvote 0
Very helpful information and solution,Domenic !
Thank you so much.
I always confuse myself how to access to ActiveX, Form controls.
It clears my cloud now. Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,198
Members
453,022
Latest member
RobertV1609

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