Hi There,
I have a userform where i have a selected number of entries. In the picture attached its 8 but it can be 5,6,7 etc.
I have created a loop to create 8 entries, each with two labels and one textbox.
Once i start the program the numbers are going to rotate, and to do this the easiest way will be to just change the caption on these labels. However i am struggling to find the correct syntax to reference and change these dynamically created labels.
Any help would be appreciated with how to update these caption names multiple times once the label has been created.
Bonus points for the code to track when a number is entered and how to match it up to its correct entry (that will rotate).
Thanks Kurt
Code:
Private Sub UserForm_Initialize()
Call UserboxSetup
End Sub
Private Sub UserboxSetup()
NoEntry = 8
UserForm2.Height = 48 + (NoEntry + 1) * (24 + 6)
For i = 1 To NoEntry
RLabel = "Forms.Label.Runner." & CStr(i)
RNumber = Sheets("MAIN_Results").Cells(5 + i, 14).Value
RName = Sheets("MAIN_Results").Cells(5 + i, 15).Value
'NumberLabel = "Label"
'Label = "LabelNo" & CStr(i)
Set Label = UserForm2.Controls.Add("Forms.Label.1", "No" & CStr(i), True)
With Label
.Name = "LabelNo" & CStr(i)
.Caption = CStr(RNumber)
.Left = 18
.Width = 24
.Top = 48 + (i - 1) * 30
.Height = 24
End With
Set Label = UserForm2.Controls.Add("Forms.Label.1", "Testsdfsdf" & i, True)
With Label
.Caption = CStr(RName)
.Left = 60
.Width = 120
.Top = 48 + (i - 1) * 30
.Height = 24
End With
'MsgBox (Label.Name)
Set Label = UserForm2.Controls.Add("Forms.TextBox.1", "Testsdfsdf" & i, True)
With Label
.Left = 198
.Width = 54
.Top = 48 + (i - 1) * 30
.Height = 24
End With
Next i
'
End Sub
I have a userform where i have a selected number of entries. In the picture attached its 8 but it can be 5,6,7 etc.
I have created a loop to create 8 entries, each with two labels and one textbox.
Once i start the program the numbers are going to rotate, and to do this the easiest way will be to just change the caption on these labels. However i am struggling to find the correct syntax to reference and change these dynamically created labels.
Any help would be appreciated with how to update these caption names multiple times once the label has been created.
Bonus points for the code to track when a number is entered and how to match it up to its correct entry (that will rotate).
Thanks Kurt
Code:
Private Sub UserForm_Initialize()
Call UserboxSetup
End Sub
Private Sub UserboxSetup()
NoEntry = 8
UserForm2.Height = 48 + (NoEntry + 1) * (24 + 6)
For i = 1 To NoEntry
RLabel = "Forms.Label.Runner." & CStr(i)
RNumber = Sheets("MAIN_Results").Cells(5 + i, 14).Value
RName = Sheets("MAIN_Results").Cells(5 + i, 15).Value
'NumberLabel = "Label"
'Label = "LabelNo" & CStr(i)
Set Label = UserForm2.Controls.Add("Forms.Label.1", "No" & CStr(i), True)
With Label
.Name = "LabelNo" & CStr(i)
.Caption = CStr(RNumber)
.Left = 18
.Width = 24
.Top = 48 + (i - 1) * 30
.Height = 24
End With
Set Label = UserForm2.Controls.Add("Forms.Label.1", "Testsdfsdf" & i, True)
With Label
.Caption = CStr(RName)
.Left = 60
.Width = 120
.Top = 48 + (i - 1) * 30
.Height = 24
End With
'MsgBox (Label.Name)
Set Label = UserForm2.Controls.Add("Forms.TextBox.1", "Testsdfsdf" & i, True)
With Label
.Left = 198
.Width = 54
.Top = 48 + (i - 1) * 30
.Height = 24
End With
Next i
'
End Sub