Looping through Controls in Multipage only working for 1 page

jparfitt87

New Member
Joined
Jul 13, 2012
Messages
23
Hi everyone hope you can help with this one,

I'm starting to tidy up my code and make is shorter instead of repeating things multiple times, so i have been learning about For loops.

I have a userform with several multipages, each page has 5 questions, which are pulled through from an excel page.

The code i was using (and which is repeated 50 times) to do this was:

LabelQ1AV.Caption = Range(FrmScope.LabelQ1AV.Name)

however I have found i can use:
Function Title()
Dim ctrl As Control
r = FrmScope.MultiPage1.Value
For Each ctrl In FrmScope.MultiPage1.Pages(r).Controls
If TypeName(ctrl) = "Label" Then
If Left(ctrl.Name, 5) = "Label" Then ctrl.Caption = Range(ctrl.Name).Value
End If

Next ctrl
End Function

The problem with the above code, and any code i've found so far, is that it only seems to work for the 1st page, when i click next the second page is blank when it should have 4 or 5 questions showing.

any help would be greatly appreciated :)
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
got it!!! For any one that needs to use something similar, this code works:

Dim ctrl As Control, r As Integer
For r = 0 To 9
For Each ctrl In FrmScope.MultiPage1.Pages(r).Controls
If TypeName(ctrl) = "Label" Then
If Left(ctrl.Name, 5) = "Label" Then ctrl.Caption = Range(ctrl.Name).Value
End If

Next ctrl
Next r
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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