ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Labels and Captions (https://www.excelbanter.com/excel-programming/384892-labels-captions.html)

[email protected]

Labels and Captions
 
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


merjet

Labels and Captions
 
For i = 1 To 5
Controls("Label" & i) = "My Caption"
Next iCt

Merjet


Vergel Adriano

Labels and Captions
 
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



" wrote:

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




All times are GMT +1. The time now is 04:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com