+ Reply to Thread
Results 1 to 4 of 4

Looping through Labels

  1. #1
    Forum Contributor
    Join Date
    01-19-2006
    Posts
    142

    Looping through Labels

    Hi all,

    I have 6 labels named lblMachine1, lblMachine2, lblMachine3, lblMachine4, lblMachine5, and lblMachine6.

    Is there a way to loop through all of these labels and populate all of them with data? I have tried the following;

    Please Login or Register  to view this content.
    Please help. Thanks all.

  2. #2
    Andrew Taylor
    Guest

    Re: Looping through Labels

    Try:
    Controls("lblMachine" & i).Caption = cbxMachine.Value

    Also, you never seem to increment i in your loop, so it will run
    for ever (unless you've omitted some lines). I'd prefer a For loop
    for this:

    For i = 1 to 6
    Controls("lblMachine" & i).Caption = cbxMachine.Value
    Next


    gti_jobert wrote:
    > Hi all,
    >
    > I have 6 labels named lblMachine1, lblMachine2, lblMachine3,
    > lblMachine4, lblMachine5, and lblMachine6.
    >
    > Is there a way to loop through all of these labels and populate all of
    > them with data? I have tried the following;
    >
    >
    > Code:
    > --------------------
    >
    >
    > Dim i%
    >
    > i = 1
    > Do
    > lblMachine(i).Caption = cbxMachine.Value
    > Loop Until i = 6
    >
    >
    > --------------------
    >
    >
    > Please help. Thanks all.
    >
    >
    > --
    > gti_jobert
    > ------------------------------------------------------------------------
    > gti_jobert's Profile: http://www.excelforum.com/member.php...o&userid=30634
    > View this thread: http://www.excelforum.com/showthread...hreadid=503266



  3. #3
    Forum Contributor
    Join Date
    01-19-2006
    Posts
    142

    Taa

    Thankyou so much for you reply, its works great now and cuts down on so much code!!

    in VB6 you can use lblMachine(i).caption but doesn't seem to work in VBA!

  4. #4
    Peter T
    Guest

    Re: Looping through Labels


    > in VB6 you can use lblMachine(i).caption but doesn't seem to work in
    > VBA!


    Only if you created a "Control-Array" of labels which is not supported in
    VBA (though you could create your own array or collection of labels).

    Regards,
    Peter T



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1