It was a mistake (inadequate testing) on my part. You'd need to add the
Redim'd array back into the Collection are remove the original element. All
said and done, it is likely all overkill simply to For Each on a set of
arrays.
Dim Coll As New Collection
Sub AAA()
Set Coll = Nothing ' clear out the collection
Dim V As Variant
Dim N As Long
Dim Arr1() As Long ' declare some dynamic arrays
Dim Arr2() As Long
Dim Arr3() As Long
Coll.Add Arr1 ' add them to the collection
Coll.Add Arr2
Coll.Add Arr3
For N = 1 To Coll.Count
V = Coll(N)
ReDim V(1 To 3) ' redim each array 1 to 3
V(1) = N * 10 ' enter some easiliy identiful values
V(2) = N * 100
V(3) = N * 1000
Coll.Add V, before:=N ' insert newly redim'd array back to
collection
Coll.Remove N + 1 ' remove original array
Next N
''''''''''''''''''''''''''''''''''
' Confirmation of correct results.
''''''''''''''''''''''''''''''''''
For N = 1 To Coll.Count
V = Coll(N)
Debug.Print "================="
Debug.Print "ARRAY: " & N, " ALLOCATED: " & IsArrayAllocated(V)
Debug.Print "VALUES OF ELEMENTS:"
Debug.Print V(1), V(2), V(3)
Next N
End Sub
Function IsArrayAllocated(A As Variant) As Boolean
'''''''''''''''''''''''''''''''''''''''''''''''''''''
' Ensure that a dynamic array is actually allocated.
'''''''''''''''''''''''''''''''''''''''''''''''''''''
On Error Resume Next
IsArrayAllocated = Not IsError(LBound(A)) And LBound(A) <= UBound(A)
End Function
And don't get started on the old "Ranges As Arrays" bit. Ranges are not
arrays.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)