Link to home
Start Free TrialLog in
Avatar of jcherry_99
jcherry_99

asked on

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.
Avatar of vinnyd79
vinnyd79

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
   
Next
Avatar of jcherry_99

ASKER

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
I can verify it works
:)
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial