Need function for checkbox in loop

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a group of check boxes and I want to do a loop if check box 1 is not checked. I want the loop to go through the other 29 check boxes and make them invisible. Any help would be great. Thanks. Mat
 
I want to do a loop so that I don't have to write "checkbox2.visible = false" for 29 checkboxes. Thanks.
 
Hi Matt
Try this provided you do not use a multipage control and with checkboxes
inside that you dont want to go through
For Each ctr in UserForm1.Controls
if TypeOf ctr is MSForms.Checkbox then
'do your stuff
end if
Next ctr

HTH
Regards
Pascal


Matt said:
I have a group of check boxes and I want to do a loop if check box 1 is
not checked. I want the loop to go through the other 29 check boxes and
make them invisible. Any help would be great. Thanks. Matt
 
I did a similar thing with textboxes and captions by
defining a textboxes collection and adding my textboxes to
it, then looping through the collection, but I suspect
there's a better way than this

dim checkboxes as new collection
checkboxes.add checkbox1
checkboxes.add checkbox2
checkboxes.add checkbox3
checkboxes.add checkbox4
checkboxes.add checkbox5

'then loop
for each checkbox in checkboxes
checkbox.value=false
next


-----Original Message-----
I have a group of check boxes and I want to do a loop if
check box 1 is not checked. I want the loop to go through
the other 29 check boxes and make them invisible. Any help
would be great. Thanks. Matt
 
Matt, Here's how I would do it if those checkboxes were all on a User Form:

Sub Checkboxes( )
Dim ctl as Control
If CheckBox1.Value = False then
For each ctl in UserForm1
If TypeName(ctl) = "CheckBox" then
ctl.Visible = False
End If
Next
CheckBox1.Visible = True
End If
End Sub

-- Dennis Eisen
 
That would work, except that I don't want all of the checkboxes on the worksheet to be invisible, just a selection of them. Any ideas? Thanks.
 
maybe name your checkboxes nicely:

checkbox01 through checkbox29

and then pick out the ones you want hidden:

Option Explicit
Private Sub CommandButton1_Click()
Dim iCtr As Long
For iCtr = 13 To 26
Me.Controls("Checkbox" & Format(iCtr, "00")).Visible = False
Next iCtr
End Sub
 
Back
Top