View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
John Green[_2_] John Green[_2_] is offline
external usenet poster
 
Posts: 58
Default Table from labels

If you are talking about Label objects created in a worksheet using the Forms toolbar, you can loop through the collection as
follows:

Sub Test()
Dim i As Integer
For i = 1 To 5
ActiveSheet.Labels(i).Caption = "This text is in every label after the loop"
Next i
End Sub

If you are talking about label controls in a userform that you have given names "Label1", "Label2", etc.

Private Sub UserForm_Click()
Dim i As Integer
For i = 1 To 5
Me.Controls("Label" & i).Caption = "This text is in every label after the loop"
Next i
End Sub


--

John Green - Excel MVP
Sydney
Australia


"T.K Kullervo" wrote in message ...
Yes, but i want to control my labels in a for-loop
Like this
For i = 0 To 5
Labels(i).Text = "This text is in every label after the loop"
Next i
How can i do this?

"John Green" wrote in message
...
If you dim an array as labels you ned to refer to it as labels, not label

(an array is not like a collection)

Dim labels(5)
labels(0) = Label1.Caption
labesl(1) = Label2.Caption

--

John Green - Excel MVP
Sydney
Australia


"T.K Kullervo" wrote in message

...
I want to refer to many labels inside a for loop. Is it possible to make

a
table from the labels like labels(5)? I tried
Dim labels(5) as label
label(0) = Label1.. And so on

How is it done right?