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
|