View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1976_] Rick Rothstein \(MVP - VB\)[_1976_] is offline
external usenet poster
 
Posts: 1
Default How to Populate an Array with a Discontiguous Values

I guess you could do this...

Dim MyArray()
MyArray = Array(1, 2, 3, , , , 7, 8, 9)

If MyArray is a Variant array as you have shown, elements 4, 5 and 6 will be
"missing" in the sense that no value is assigned to them at all... they are
not empty or null, they just don't have anything assigned to them. You will
get an error if you try to address them although you can test for that using
the IsError function. If you declare your array with an actual type
(Integer, Long, String, etc.), then elements 4, 5, and 6 will take on the
default value for those data types (0, 0, "", etc.).

Rick


"PMC1" wrote in message
...
Hi,

Using Excel 2003 VBA I'm looking to Populate a 1 dimensional Array
with a Discontiguous values.

For example, instead of fully declaring a range like this
Array(1,2,3,7,8,9) I want ot pupulate the array by declaring the range
and then use something like a loop to populate the array e.g.

Dim myArRanges(1 to 3, 7 to 9)
Redim MyArray(myArRanges)

Could anyone suggest how this might be done.

Thanks

..pc