Josh
Josh

Reputation: 265

Shortcut to call multiple userform option buttons?

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)

Upvotes: 0

Views: 497

Answers (2)

LimaNightHawk
LimaNightHawk

Reputation: 7083

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.

Upvotes: 1

Trung Tran
Trung Tran

Reputation: 13721

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

Upvotes: 0

Related Questions