View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default ReDim Object array as parameter of Variant array

Hi All,

I want to Redim Preserve an object array to be stored in a variant array. I
can't figure how to do this, if indeed it's possible

Public vArr(1 To 4, 0 To 1)

Sub test()
Dim a1(1 To 10) As Range
Dim a2(1 To 12) As Range
Dim a4(1 To 14) As Range

For i = 1 To 10
Set a1(i) = Cells(i * 2, 1)
Next

vArr(1, 0) = a1
vArr(2, 1) = a2
vArr(4, 0) = a4

Set vArr(2, 1)(5) = [d7]

For i = 1 To 4
For j = 0 To 1
If Not IsEmpty(vArr(i, j)) Then
Debug.Print i; j, UBound(vArr(i, j))
Else: Debug.Print i; j, "Empty"
End If
Next
Next

Debug.Print vArr(1, 0)(10).Address
Debug.Print vArr(2, 1)(5).Address

End Sub


The first two dimensions of the variant array are known in advance and can
be fixed. In the above example the object arrays, a1, a2, & a4 are pre -
dimensioned. That's NOT want I want to do. Instead I want to be able to do
something like this:

x = 20
ReDim Preserve vArr(3, 0)(1 to x) as Range

Obviously this isn't possible - but is there a way?

As an alternative I can do the following

Public rArr() As Range

x = 20
ReDim Preserve rArr(1 to 4, 0 to 1, 1 to x)

Where Ubound of the last dimension, (the "x" in above) must always be the
largest qty of objects assigned to any of the preceding dimensions. This
seems inefficient as the number of objects in the last dimension varies from
none to hundreds. Yet I need an indexing method to set & get my object
arrays as provided by the first two "fixed" dimensions. Maybe there's an
alternative approach?

TIA for suggestions,
Peter T