![]() |
arrays in arrays
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. |
arrays in arrays
jacob wrote:
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 |
arrays in arrays
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 On Fri, 27 Aug 2004 06:35:23 -0700, "jacob" wrote: 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. |
arrays in arrays
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 On Fri, 27 Aug 2004 06:35:23 -0700, "jacob" wrote: 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. . |
arrays in arrays
Thx for the effort.
-----Original Message----- jacob wrote: 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 . |
All times are GMT +1. The time now is 05:20 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com