Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing a series of controls in Excel VBA

Status
Not open for further replies.

afryer

Programmer
Mar 9, 2004
207
GB
Hi All,

I am producing a spreadsheet which contains a series of controls in column B,named CheckBox1....CheckBoxn (not very original I know, but there is about 600 of them and I can't be bothered to change them by hand).

What I need to be able to do is to reference the controls based on the column number that is selected, for example if the user clicked on row 24 then I would need to reference CheckBox24.

I can reference the individual objects by using me.CheckBox1, but I need to have an object that I can use, i.e

l_value = lCheckBoxObject.Value

will return the current state of the check box, which can be any of the check boxes from 1..n.

Does anybody have any idea how to do this?

Thanks
 
You may have to play with the Shapes collection.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Try this out. The exact solution may depend on whether you are using userform checboxes or control checkboxes

For Each ctrl In ActiveSheet.Shapes

If Left(ctrl.Name, 8) = "CheckBox" And
Mid(ctrl.Name, 9) = ActiveCell.Row Then

ctrl.DrawingObject.Object.Value = True

End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top