Simple Way To Step Through Checkboxes

A

Andrew

Folks,

Im hoping this is a simple question and Im just being dense.

I have a user form with around 30 check boxes, to select different
graphs to be displayed or hidden. I am wanting to cycle through the
checkboxes and then for each, if the user has checked the box display
the relevant series on the graphs. So the question is how do I step
from checkbox to checkbox to determine its value.

Thanks for any help,

Andrew
 
S

Shailesh Shah

Hi,
Try this,

Dim ctl As Object
For Each ctl In userform1.Controls

'if within userform's codmodule
'For Each ctl In me.Controls

If TypeName(ctl) = "CheckBox" Then
If ctl.Value Then MsgBox ctl.Name & " : marked"
End If
Next


Regards,
Shah Shailesh
http://members.lycos.co.uk/shahweb/


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
P

Paul Robinson

Hi,
Not tested but try this:

Dim myControl As MSForms.Control
For Each myControl In myForm.Controls
If TypeOf myControl Is MSForms.CheckBox Then
'something to do with myControl.Value
End If 'typeof
Next myControl

regards
Paul
 
O

onedaywhen

Well, the Userform object has a Controls collection which you could
loop through and do a TypeOf comparison to test which are CheckBox.
However, you would make things easier on yourself if in the form's
_Activate event you put all the relevant checkboxes into your own
Collection, array or similar, then you'd *know* where to look for them
later.
 
Top