Returning to INdexing labels and coloring them by group

A couple of days ago I asked about how to give all labels on a form the same background color. I received 2 excellent replies; unfortunately, one of them does not work for excel.

It is this one

Pub sub command1_click()
Dim i as integer
for i = 0 to Userform3.label1.ubound
next i
end sub

The problem seems to be that it will not let me see or create an indexed label with the same name.

I've tired
dim a as label 'works

but I cannot put anything on the form with the same name and if there is a way to create and use an array of labels I surely don't know how to do it.

Please help

Vinnyd79 if you are around, this was originally your code.
Who is Participating?
PAQed with no points refunded (of 50)

Community Support Moderator
You have to set the index property on the first label to 0.
VBA does not support control arrays. In VBA you can use this:

Dim c As Control

For Each c In Controls

    If TypeOf c Is msforms.Label Then
        c.BackColor = &HCC8080
    End If
jcherry_99Author Commented:
To Vinny

The problem is that I cannot set the index to zero. I don't think excell does that. Nor do I know how to get excel to copy labels on a form so that they all have the same name.

Perhaps VB can do that, but I don't think excel can

Take good care

I can verify it works
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.