Loop through labels on mulitpage control?

taylorpa5

New Member
Joined
May 9, 2015
Messages
21
Good Morning,

I have a multipage control that will be utilizing the same label names on each page of the control (about 9 pages total). Each page however will have a different caption name for the label (i.e Label16.Caption on Page 1 will read "ABC"; the Label16.Caption on Page 2 will read "DEF" and so on. Each label caption is based on a Dim'd Range.

Without having to do the below code for each page, Is there a way to loop through the pages to fill in the caption names for each label?

Code:
 	Option Explicit

Dim LTE1C As Object, LTE2C As Object, LTE3C As Object, LTE4C As Object
Dim POWER As Object, ANTENNAS As Object, TMAS As Object, SURGE As Object, FIBER As Object, MISC As Object, NSB As Object

Private Sub UserForm_Initialize()

Set LTE1C = Worksheets("CONTROLSBOM").Range("LTE1CBOM")
Set LTE2C = Worksheets("CONTROLSBOM").Range("LTE2CBOM")
Set LTE3C = Worksheets("CONTROLSBOM").Range("LTE3CBOM")
Set LTE4C = Worksheets("CONTROLSBOM").Range("LTE4CBOM")
Set POWER = Worksheets("CONTROLSBOM").Range("POWERANDCONVERTERS")

Label3.Caption = Date & ": " & Time
Label5.Caption = Environ("Username")

'SET UP MULTIPAGES

MultiPage1.Page1.Label16.Caption = LTE1C(1, 1)
MultiPage1.Page1.Label17.Caption = LTE1C(1, 6)
MultiPage1.Page1.Label18.Caption = LTE1C(1, 5)

MultiPage1.Page1.Label19.Caption = LTE1C(2, 1)
MultiPage1.Page1.Label20.Caption = LTE1C(2, 6)
MultiPage1.Page1.Label21.Caption = LTE1C(2, 5)

MultiPage1.Page1.Label22.Caption = LTE1C(3, 1)
MultiPage1.Page1.Label23.Caption = LTE1C(3, 6)
MultiPage1.Page1.Label24.Caption = LTE1C(3, 5)

MultiPage1.Page1.Label25.Caption = LTE1C(4, 1)
MultiPage1.Page1.Label26.Caption = LTE1C(4, 6)
MultiPage1.Page1.Label27.Caption = LTE1C(4, 5)

MultiPage1.Page1.Label28.Caption = LTE1C(5, 1)
MultiPage1.Page1.Label29.Caption = LTE1C(5, 6)
MultiPage1.Page1.Label30.Caption = LTE1C(5, 5)

MultiPage1.Page1.Label31.Caption = LTE1C(6, 1)
MultiPage1.Page1.Label32.Caption = LTE1C(6, 6)
MultiPage1.Page1.Label33.Caption = LTE1C(6, 5)

MultiPage1.Page1.Label34.Caption = LTE1C(7, 1)
MultiPage1.Page1.Label35.Caption = LTE1C(7, 6)
MultiPage1.Page1.Label36.Caption = LTE1C(7, 5)

MultiPage1.Page1.Label37.Caption = LTE1C(8, 1)
MultiPage1.Page1.Label38.Caption = LTE1C(8, 6)
MultiPage1.Page1.Label39.Caption = LTE1C(8, 5)

MultiPage1.Page1.Label40.Caption = LTE1C(9, 1)
MultiPage1.Page1.Label41.Caption = LTE1C(9, 6)
MultiPage1.Page1.Label42.Caption = LTE1C(9, 5)

MultiPage1.Page1.Label43.Caption = LTE1C(10, 1)
MultiPage1.Page1.Label44.Caption = LTE1C(10, 6)
MultiPage1.Page1.Label45.Caption = LTE1C(10, 5)

MultiPage1.Page1.Label46.Caption = LTE1C(11, 1)
MultiPage1.Page1.Label47.Caption = LTE1C(11, 6)
MultiPage1.Page1.Label48.Caption = LTE1C(11, 5)

MultiPage1.Page1.Label49.Caption = LTE1C(12, 1)
MultiPage1.Page1.Label50.Caption = LTE1C(12, 6)
MultiPage1.Page1.Label51.Caption = LTE1C(12, 5)

MultiPage1.Page1.Label52.Caption = LTE1C(13, 1)
MultiPage1.Page1.Label53.Caption = LTE1C(13, 6)
MultiPage1.Page1.Label54.Caption = LTE1C(13, 5)

MultiPage1.Page1.Label55.Caption = LTE1C(14, 1)
MultiPage1.Page1.Label56.Caption = LTE1C(14, 6)
MultiPage1.Page1.Label57.Caption = LTE1C(14, 5)

MultiPage1.Page1.Label58.Caption = LTE1C(15, 1)
MultiPage1.Page1.Label59.Caption = LTE1C(15, 6)
MultiPage1.Page1.Label60.Caption = LTE1C(15, 5)

End Sub


Please ask for more detail if needed. I'll be monitoring this thread through the the morning.

Thank you for the assistance.

pt​
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
One way, Assuming you are writing inside the UserForm code module then
Code:
For Each pg In MultiPage1.Pages
	'pg.Caption = MyPage - sample statement
	'other code here
Next
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

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