Excel VBA array of checkboxes

  • Thread starter Thread starter Eliezer
  • Start date Start date
E

Eliezer

I have 44 checkboxes on a VBA Excel form that I dragged
there from the Toolbox. I named them all rep1_cb,
rep2_cb, rep3_cb, ... rep44_cb.

I want to add a button to the forum to un/check all
checkboxes within this "group". Is there some way to
store them all within an array - or create some sort of
loop without having to individually change the value of
each and every one of them?

Thanks!
Eliezer
 
Eliezer

Here's a simple for each loop that looks at the names of all controls and
reverses the values for the ones you designated as "rep" control check
boxes:


Private Sub cmdCheckBoxes_Click()
Dim ctrl As Control

For Each ctrl In Me.Controls
If Left(ctrl.Name, 3) = "rep" Then
ctrl.Value = Not ctrl.Value
End If
Next

End Sub
 
Charles,

Excellent! Thanks!
Eliezer

-----Original Message-----
Eliezer

Here's a simple for each loop that looks at the names of all controls and
reverses the values for the ones you designated as "rep" control check
boxes:


Private Sub cmdCheckBoxes_Click()
Dim ctrl As Control

For Each ctrl In Me.Controls
If Left(ctrl.Name, 3) = "rep" Then
ctrl.Value = Not ctrl.Value
End If
Next

End Sub


--
Charles
www.officezealot.com





.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top