OptionButtons collection not recognized

Corni

Active Member
Joined
Mar 2, 2002
Messages
328
I have a user form in Excel XP with two frames and two groups of option buttons, 17 in the first frame and two in the second frame. To better handle the two groups I assigned the GroupName property for the two groups as well. When I am trying to run this code:

For Each opt In UserForm1.OptionButtons
'do something
Next opt

I get following message 'Method or data member not found' (OptionButtons is highlighted). Any idea what goes wrong?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
That is because there is not an OptionButtons collection for a UserForm.

You must access the Controls collection to do what you are looking for.

<font face=Courier New>    <SPAN style="color:#00007F">Dim</SPAN> ctr <SPAN style="color:#00007F">As</SPAN> Control
    
    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ctr <SPAN style="color:#00007F">In</SPAN> Me.Controls
        <SPAN style="color:#00007F">If</SPAN> TypeName(ctr) = "OptionButton" <SPAN style="color:#00007F">Then</SPAN>
            <SPAN style="color:#007F00">'do some code here</SPAN>
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">Next</SPAN></FONT>
 
Upvote 0
Perhaps you could modify your code as shown within:

Private Sub CommandButton1_Click()
XX = UserForm1.Frame1.Controls.Count
For Each Opt In UserForm1.Frame1.Controls

MsgBox XX
XX = XX - 1

Next Opt

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top