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
userform3.label1.item(i).backcolor=rgb(240,100,0)
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

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

modulo
Community Support Moderator
0
 
vinnyd79Commented:
You have to set the index property on the first label to 0.
0
 
Erick37Commented:
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
   
Next
0
 
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

Jerome
0
 
Erick37Commented:
I can verify it works
:)
0
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.