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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkboxes 1

Status
Not open for further replies.

FJAY

Programmer
Apr 23, 2003
106
0
0
CA
Good Morning - I created a form userform in excel with about 20 checkboxes and I will like to set the value of each checkboxes on the click of a button without having to spell out the name of each checkboxes. Is this possible. I know in Visual Basic I can create an array of checkboxes. But I don't know how to do this in excel vba. I created each checkbox separetly. Thanks.
 
The basic idea:
For i = 1 To 20
Me.Controls("CheckBox" & i).Value = True
Next i

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
It won't work because I've changed the names of the checkboxes from checkbox1 to i.e chkUSP, etc.
 
You may consider playing with an array of names:
myCBs = Array("chkUSP", ...)
For Each strCB In myCBs
Me.Controls(strCB).Value = True
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
This ought to work for you (at least it does in EXCEL 2002) and is fairly generic.

For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "CheckBox"
ctl.Value = True
End Select
Next ctl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top