Thread: VBA arrays
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Sheeloo[_3_] Sheeloo[_3_] is offline
external usenet poster
 
Posts: 1,805
Default VBA arrays

A static array is an array that is sized in the Dim statement that declares
the array. E.g.,
Dim StaticArray(1 To 10) As Long
You cannot change the size or data type of a static array. When you Erase a
static array, no memory is freed. Erase simple set all the elements to their
default value (0, vbNullString, Empty, or Nothing, depending on the data type
of the array).

A dynamic array is an array that is not sized in the Dim statement. Instead,
it is sized with the ReDim statement. E.g.,
Dim DynamicArray() As Long
ReDim DynamicArray(1 To 10)
-----------------------------------------------------------------------
This is an extract from Chip Person's article on VBA Arrays. Pl. visit
http://www.cpearson.com/excel/VBAArrays.htm for the complete excellent
article..
"Matt" wrote:

While there you may also like to look at Arrays Formulas....

I'm trying to get my head around lists (arrays?) in VBA. Lets say I
want to create an array of random numbers whose length is defined by
the user. Is this the right idea?

1 - It would ask the user how long the array should be.
2 - Then starting with an empty array, it would run through a for loop
as many times as defined by the user, each time appending a new random
number to the end.

I can't seem to figure out the right way to use arrays in VBA. Is
array(a, b, c) the best way to create them? How then do you add
another number to it? Or access the nth value in the array?