Returning to INdexing labels and coloring them by group

Posted on 2004-10-26
Last Modified: 2010-05-02
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.
Question by:jcherry_99
    LVL 28

    Expert Comment

    You have to set the index property on the first label to 0.
    LVL 32

    Expert Comment

    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

    Author Comment

    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

    LVL 32

    Expert Comment

    I can verify it works

    Accepted Solution

    PAQed with no points refunded (of 50)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now