Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing the font for part of an axis label, not the whole label. amy45 Charts and Charting in Excel 2 April 5th 23 01:11 PM
Userform Label Steve[_9_] Excel Discussion (Misc queries) 7 October 29th 07 09:51 PM
Label Caption Just Wont Work on UserForm K[_3_] Excel Programming 2 September 15th 03 03:29 PM
Making a TextBox look and feel like a Label in a userform ijb Excel Programming 0 July 30th 03 12:26 AM
Making a TextBox look and feel like a Label in a userform Mike NG Excel Programming 0 July 29th 03 11:52 PM


All times are GMT +1. The time now is 01:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"