Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
changing selected label on userform w/ a variable
I am trying to change the text of the labels that I have
on a userform and would like to refer to these labels using a variable so that I can create a loop. ie. userform_.labelx=____ where x=some integer. I have tried this but it hangs everytime. Thanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
changing selected label on userform w/ a variable
"mike k" wrote in message
... I am trying to change the text of the labels that I have on a userform and would like to refer to these labels using a variable so that I can create a loop. ie. <snip Try these ideas: Private Sub UserForm_Click() 'you can use the Controls collection like this '(assumes they are named Label1, Label2, etc.) Dim i For i = 1 To 2 UserForm1.Controls("Label" & CStr(i)).Caption = "something" Next i 'or this i = 0 Dim ctl As Control For Each ctl In UserForm1.Controls If TypeName(ctl) = "Label" Then i = i + 1 ctl.Caption = "Label" & CStr(i) End If Next 'or create a sub-collection of labels to use Dim colLabels As New Collection For Each ctl In UserForm1.Controls If TypeName(ctl) = "Label" Then colLabels.Add ctl, ctl.Caption '(2nd arg must be a unique string) End If Next colLabels("Label1").Caption = "this" colLabels("Label2").Caption = "that" End Sub '--- Bob |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Changing the font for part of an axis label, not the whole label. | Charts and Charting in Excel | |||
Userform Label | Excel Discussion (Misc queries) | |||
Label Caption Just Wont Work on UserForm | Excel Programming | |||
Making a TextBox look and feel like a Label in a userform | Excel Programming | |||
Making a TextBox look and feel like a Label in a userform | Excel Programming |