arrays in arrays

  • Thread starter Thread starter jacob
  • Start date Start date
J

jacob

Hi,
Have a 2D array where each element contain a new 2D
array. Is it possible to perform a 'Redim Preserve' on an
array contained in the "mother" array? If so, what is the
proper syntax?

Any help appreciated.
 
jacob said:
Hi,
Have a 2D array where each element contain a new 2D
array. Is it possible to perform a 'Redim Preserve' on an
array contained in the "mother" array? If so, what is the
proper syntax?

Any help appreciated.
The following seems to me kludgy, but the straightforward

ReDim Preserve motherArray(1,1)(3,5) wouldn't compile--syntax error

Sub abc()
Dim motherArray() As Variant
Dim containedArray() As Variant
Dim arrtemp() As Variant
Dim i As Long, j As Long
ReDim motherArray(1 To 2, 1 To 2)
containedArray = Range("A1:D3")
For i = 1 To 2: For j = 1 To 2
motherArray(i, j) = containedArray
Next: Next
arrtemp = motherArray(1, 1)
'Debug.Print UBound(motherArray(1, 1), 2) 'Check original UBound
ReDim Preserve arrtemp(3, 5)
motherArray(1, 1) = arrtemp
'Debug.Print UBound(motherArray(1, 1), 2) 'Checked changed UBound
'Debug.Print motherArray(1, 1)(3, 4) 'Check preservation
Erase arrtemp
End Sub

Alan Beban
 
I couldn't get this to work. Assuming you have something like:

Dim a, b, c, d, z
ReDim a(0 to 2)
ReDim b(0 to 2)
ReDim c(0 to 2)
ReDim d(0 to 2)

a(0) = b
a(1) = c
a(2) = d

The syntax would be somthing like

Redim Preserve a(1)(0 to 8)

but it gives a syntax error and won't compile.

I had to do something like this:

z = a(1)
Redim Preserve z(0 to 8)
a(1) = z
 
Thx for helping.
-----Original Message-----
I couldn't get this to work. Assuming you have something like:

Dim a, b, c, d, z
ReDim a(0 to 2)
ReDim b(0 to 2)
ReDim c(0 to 2)
ReDim d(0 to 2)

a(0) = b
a(1) = c
a(2) = d

The syntax would be somthing like

Redim Preserve a(1)(0 to 8)

but it gives a syntax error and won't compile.

I had to do something like this:

z = a(1)
Redim Preserve z(0 to 8)
a(1) = z




.
 
Thx for the effort.
-----Original Message-----

The following seems to me kludgy, but the straightforward

ReDim Preserve motherArray(1,1)(3,5) wouldn't compile-- syntax error

Sub abc()
Dim motherArray() As Variant
Dim containedArray() As Variant
Dim arrtemp() As Variant
Dim i As Long, j As Long
ReDim motherArray(1 To 2, 1 To 2)
containedArray = Range("A1:D3")
For i = 1 To 2: For j = 1 To 2
motherArray(i, j) = containedArray
Next: Next
arrtemp = motherArray(1, 1)
'Debug.Print UBound(motherArray(1, 1), 2) 'Check original UBound
ReDim Preserve arrtemp(3, 5)
motherArray(1, 1) = arrtemp
'Debug.Print UBound(motherArray(1, 1), 2) 'Checked changed UBound
'Debug.Print motherArray(1, 1)(3, 4) 'Check preservation
Erase arrtemp
End Sub

Alan Beban
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top