Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Looping through Labels

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gti_jobert - 20 Jan 2006 10:11 GMT
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.

Signature

gti_jobert

Andrew Taylor - 20 Jan 2006 10:24 GMT
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

> Hi all,
>
[quoted text clipped - 23 lines]
> gti_jobert's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=30634
> View this thread: http://www.excelforum.com/showthread.php?threadid=503266
gti_jobert - 20 Jan 2006 10:42 GMT
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!

Signature

gti_jobert

Peter T - 20 Jan 2006 12:17 GMT
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.