Excel Checkbox Question. Please help me write a macro that will selectively uncheck certain boxes within a named range.

kev23f

New Member
Joined
Mar 4, 2010
Messages
4
So i have a row of 7 checkboxes, inserted using “Insert – Form Controls” dialog in excel 2007.
Each checkbox sits above a cell, and each checkbox has been formatted so that it has a “cell link” to the cell directly beneath it.
The checkboxes are not grouped or anything, they are all separate.
I have several rows of checkboxes similar to this.

I would like to create a macro that when run, will uncheck all the boxes that are within a certain range, for example, from A1 to G1.

I have found VBA that will clear all checkboxes on a sheet, but the key for me is to be able to specify which checkboxes get cleared when i run the macro.
 
Possibly something like this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG26Jun45
[COLOR="Navy"]Dim[/COLOR] ctrl [COLOR="Navy"]As[/COLOR] OLEObject, Rng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Cb [COLOR="Navy"]As[/COLOR] CheckBox
[COLOR="Navy"]Set[/COLOR] Rng = Range("H2:H10")
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] ctrl [COLOR="Navy"]In[/COLOR] ActiveSheet.OLEObjects
    [COLOR="Navy"]If[/COLOR] TypeName(ctrl.Object) = "CheckBox" And Not Intersect(ctrl.TopLeftCell, Rng) [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
        ctrl.Object.Value = False
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Cb [COLOR="Navy"]In[/COLOR] ActiveSheet.CheckBoxes
    [COLOR="Navy"]If[/COLOR] Not Intersect(Cb.TopLeftCell, Rng) [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
        Cb.Value = False
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Cb

[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Awesome MickG,

You are a Scholar and a Gentleman, outstandingly knowledgeable!!!:pray:

Thank you sooo much!

Kind greetings!
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,289
Members
449,077
Latest member
Rkmenon

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