I know we can define single dimension array in excel VBA using the following
GroupCols = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L")
How can you predefine multi- dimensional array in the same manner?
Also I want to keep track of certain levels in the following manner
Level[16][0]
Level[16][1]
Level[16][2]
Level[8][0]
Level[8][1]
Level[8][2]
Level[7][0]
Level[7][1]
Level[7][2]
The first index defines the level and so may not be consecutive…like after 16 there is straight 8 and so on. For each i need 3 info which is 0,1,2 second indexes.
Can anyone guide me on how to achieve the same in excel VBA?
You can’t have non-consecutive indices in an array like that. If you do only use a non-consecutive subset of the indices, then all the other elements will be empty but still use up storage space, which is both inefficient and error-prone (
LaunchMissile = Levels(17,1), whoops!).What you’re looking for is the Dictionary object. Before use, must set reference as follows: Tools > References > check Microsoft Scripting Runtime.
Example:
Note that a Collection object could also do the trick. Advantage: native to VBA, so no need to set reference. Disadvantage: Key is write-only, which can be quite awkward.