![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Posts: 42
|
I have the following code:
Range("A2").Select Label1.Caption = ActiveCell.Value ActiveCell.Offset(1, 0).Select Label2.Caption = ActiveCell.Value ActiveCell.Offset(1, 0).Select Label3.Caption = ActiveCell.Value ActiveCell.Offset(1, 0).Select Label4.Caption = ActiveCell.Value ActiveCell.Offset(1, 0).Select Label5.Caption = ActiveCell.Value ActiveCell.Offset(1, 0).Select Label6.Caption = ActiveCell.Value ActiveCell.Offset(1, 0).Select Label7.Caption = ActiveCell.Value ActiveCell.Offset(1, 0).Select Label8.Caption = ActiveCell.Value ActiveCell.Offset(1, 0).Select Label9.Caption = ActiveCell.Value ActiveCell.Offset(1, 0).Select which goes on for lots of instances. I know it is a newbie question but how can I shorten it so that it goes through each label in turn? Thanks |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Posts: 255
|
It's actually not that "newbie" of a question. To do this in VB is simple; you would just create an object array and use a for next loop. However, in VBA you cannot create an object array. I had this same question a while ago and figured out how to do this but I haven't used it in while so I've forgotten. I'll be back with an answer...
Dave |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Posts: 255
|
Slim--
See this link or search control arrays in the archives. http://www.mrexcel.com/board/viewtop...c=3611&forum=2 Dave |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
If your labels are on a worksheet, you can use something like this:
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|