Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop through Labels and Text Boxes within module code
I am trying to change Label Captions and Text Box Text in a loop located in
my module. For example I have a form that has 40 labels. I want to change the text in the first "m" number of labels. At first I was hopeing to use something like the following for i = 1 to m UserForm1."Label" & i.Caption = worksheets("Sheet1").cells(3,i).value Next i Excell does not seam to want to consummate "Label" & i to Label1 and recognize it as a object within UserForm1. At the suggestion of a buddy and another posting I was hopeing to do it defining a collection of Label objects with the following code, however the "Set" statement doesn't seam to be valid for a collection. Dim Labs() As New Collection Dim labelcount As Integer Dim ctl As Control labelcount = 0 For Each ctl In UserForm1.Controls If TypeName(ctl) = "Label" Then labelcount = labelcount + 1 ReDim Preserve Labs(1 To labelcount) Set Labs(labelcount) = ctl End If Next ctl For i = 1 To m Labs(i).Caption = "cool" Next i I would appreciate any help on the matter, the end less dead ends are driving me to madness. I'm useing Office 2000 and am upgradeing to Office 2003 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop through Labels and Text Boxes within module code
Dan,
Access via the Controls collection, like UserForm1.Controls("Label" & i).Caption = worksheets("Sheet1").cells(3,i).value -- HTH RP (remove nothere from the email address if mailing direct) "Dan Gardner" wrote in message ... I am trying to change Label Captions and Text Box Text in a loop located in my module. For example I have a form that has 40 labels. I want to change the text in the first "m" number of labels. At first I was hopeing to use something like the following for i = 1 to m UserForm1."Label" & i.Caption = worksheets("Sheet1").cells(3,i).value Next i Excell does not seam to want to consummate "Label" & i to Label1 and recognize it as a object within UserForm1. At the suggestion of a buddy and another posting I was hopeing to do it defining a collection of Label objects with the following code, however the "Set" statement doesn't seam to be valid for a collection. Dim Labs() As New Collection Dim labelcount As Integer Dim ctl As Control labelcount = 0 For Each ctl In UserForm1.Controls If TypeName(ctl) = "Label" Then labelcount = labelcount + 1 ReDim Preserve Labs(1 To labelcount) Set Labs(labelcount) = ctl End If Next ctl For i = 1 To m Labs(i).Caption = "cool" Next i I would appreciate any help on the matter, the end less dead ends are driving me to madness. I'm useing Office 2000 and am upgradeing to Office 2003 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop through Labels and Text Boxes within module code
Thanks your awsome, I've been pulling my hair out for weeks on this. and now
I feel like an idiot |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Data labels switch to text boxes on negative values | Charts and Charting in Excel | |||
code in module A to not execute a Worksheet_SelectionChange sub of another module | Excel Discussion (Misc queries) | |||
XL97: Position text boxes (or data labels) w/out VBA | Charts and Charting in Excel | |||
MSForm 2 - Creating labels and text boxes at run time | Excel Programming | |||
Updating form labels from code in a module | Excel Programming |