![]() |
#1
|
|||
|
|||
![]() Hello All, Is something like the below possible? Code:
Dim i as Byte Dim Rank1, Rank2, Rank3 as String for i = 1 To 3 Rank&i = 'cell reference value next i Wries |
#2
|
||||
|
||||
![]()
In VBScript you can do something like that, Wries. I don't know of a way to do it directly in VBA. But depending on what you need, you may not have to. Do you just need to set three (or more) values in a loop? If so, there are several really good ways.
1) Use an "array". An array is a series of variables with a name plus a number, any number you like from x to y. In your example it would work like this: Code:
Dim Rank(1 To 3) For i = 1 to 3 Rank(i) = 'cell reference value Next i 2) Use a collection. A collection is like an array but more flexible. For one thing you can name the items in a collection, as well as number them. For another, items of a collection can be objects, not just scalar values (numbers or character strings, I mean). And you don't have to decide ahead of time how many you want. With an array you have to use the Dim statement to give the array a predetermined lower and upper bound; but a collection doesn't have to know ahead of time how many items it'll hold. Like this: Code:
Set Coll = New Collection For i = 1 to 3 Coll.Add ActiveWorksheet.Rows(i + 1) Next i 3) Use a worksheet. If for some reason you don't like either of the above two choices, you can store the data in a spare worksheet, if you have one handy. Code:
Set os = ThisWorkbook.Worksheets("Sheet3") For i = 1 to 3 os.Cells(i, 5).Value = "some value" Next i Are any of those a help? |
#3
|
|||
|
|||
![]()
Dear Bob,
Thank you very much for the reply. Of course the array would be perfect solution. I am using arrays often no idea why i didnt associated them with this problem. Kind regards, Peter |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
JUST ME | Word VBA | 4 | 03-25-2014 06:56 AM |
Need help sumif with variable for VBA | jingo | Excel Programming | 4 | 01-23-2014 11:02 AM |
![]() |
MJP143 | Excel | 1 | 02-11-2013 05:07 AM |
![]() |
tinfanide | Excel Programming | 2 | 06-10-2012 10:17 AM |
Variable fields? | Emalee77 | PowerPoint | 0 | 01-30-2011 05:58 PM |