Looping Through Frames Looping through Option Buttons

marl4

New Member
Joined
Jul 30, 2018
Messages
3
Hi all! I am relatively skilled with VBA but cannot find a better way to do this...
I have a userform with 63 frames. Currently I'm transferring my data out with 63 iterations of the following:

For Each ctrl In Frame1.Controls


If ctrl.Value = True Then
home.Offset(j, icol) = ctrl.Caption
End If


Next
j = j + 1

The subsequent lines are for Frame2, Frame 3, etc all the way up to 63. My question is this:
How do I write this so that I can do a larger loop outside of this bit of code to have all 63 in one loop? i have tried variations of the following but I am not dimensioning something correctly.
Do until MyFrame = 63
For each ctrl in "Frame" & MyFrame & ".Controls"
'code to look at each option button
'Next
Loop

Please help direct me towards a more efficient way to do this! Thank you!!
M
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi,
welcome to forum


try

Code:
Dim ctrl As msforms.Control
Dim i As Integer


For i = 1 To 63
 For Each ctrl In Me.Controls("Frame" & i).Controls
 
    '
    'your code
    '
    
 Next ctrl
Next i

Dave
 
Upvote 0
Hi,
welcome to forum


try

Code:
Dim ctrl As msforms.Control
Dim i As Integer


For i = 1 To 63
 For Each ctrl In Me.Controls("Frame" & i).Controls
 
    '
    'your code
    '
    
 Next ctrl
Next i

Dave

Hi Dave - Thank you for this.

My frames are a series of Yes, No, or NA answers. When I use your code, I think it doesn't know to look at each 3 from the specific frame - it only output 1 answer where I expected 63 answers. Does that make sense?
 
Upvote 0

Forum statistics

Threads
1,215,359
Messages
6,124,488
Members
449,165
Latest member
ChipDude83

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