CheckBoxes vs. OptionButtons in VBA
I have a UserForm in Excel with 100 checkboxes. At runtime, depending on which CommandButton a user clicks on, I get the contents of a particular column on one of 3 sheets and use those values for the Caption property of some (or all) of the CheckBoxes and hide the rest. My problem is that I also have 2 OptionButtons on the form, and my code for finding the Checkboxes and setting the Captions is not distinguishing between them and the CheckBoxes.
Code:
Dim i As Integer
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.CheckBox Then
If i < intNumChoices Then
ctl.Caption = astrChoices(i)
ctl.Visible = True
i = i + 1
Else
ctl.Visible = False
End If
End If
Next
(Please, no comments about the Hungarian notation. I still prefer it! :-)
When I run this, the first two values in astrChoices() are put on the OptionButtons. How do I distinguish between the two different types of controls?
Thanks.