Labels and Captions

C

cougarfighter

Hey all,
I realize this should be easy, but I'm not finding the solution.
I have labels that are named Label1, Label2, Label3, ...

I want a loop to set the label's caption such as
For i = 1 to 5
Label(i).caption = "My Caption"
Next i

Thanks
 
G

Guest

Assuming you have exactly 5 label controls and they all are named as LabelX,

Dim i As Integer
For i = 1 To 5
Me.Controls("Label" & i).Caption = "My Caption"
Next i


If you wanted to just go through all label controls in the form, then
something like this might give you an idea

Dim c as control
For each c in Me.Controls
If TypeOf c is MSForms.Label then
c.Caption = "My Caption"
End If
Next c
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top