Question

I have a userform with 25 OptionButton (OptionButton1, OptionButton2, etc..)

As it is, to have each of these options called, I created private subs OptionButton1_Click, OptionButton2_Click, etc..

Is there any way to access the different options without creating 25 different subs? (i.e. OptionButton[x]_Click)

Was it helpful?

Solution

I think the short answer is no, but have a look here for an interesting work-around. You could essentially fake a control array.

Besides what is mentioned in the post, you may additionally want to consider storing some kind of Tag in the OptionButton.Tag so that when it is clicked you can (if you wish) know which OptionButton was clicked.

OTHER TIPS

You could loop through all the option buttons. For example:

for i = 1 to 25

    If Controls("OptionButton" & i).Value = True Then

       'perform operation if OptionButton is clicked

     End If

Next i
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top