A 190,000 x 4 variant array requires only 12MB of memory. Add the
array overhead and the memory requirement goes up by 20+190000*(4+4)
*bytes*
Maybe, the problem is caused by the OS running out of some other kind
of memory.
In any case, the code below works just fine in WinXP/XL2003.
Option Explicit
Sub testIt()
Dim i As Long, j As Long, Arr1(1 To 190000, 1 To 4) As Variant, _
Arr2() As Variant
ReDim Arr2(LBound(Arr1, 2) To UBound(Arr1, 2), _
LBound(Arr1) To UBound(Arr1))
For i = LBound(Arr2) To UBound(Arr2)
For j = LBound(Arr2, 2) To UBound(Arr2, 2)
Arr2(i, j) = i * j
Next j
Next i
For i = LBound(Arr2) To UBound(Arr2)
For j = LBound(Arr2, 2) To UBound(Arr2, 2)
Arr1(j, i) = Arr2(i, j)
Next j
Next i
End Sub
--
Regards,
Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
In article ,
says...
I'm using the following function to transpose a 2d array in Excel 2003.
Public Function TransposeArray(arrIn As Variant)
Dim i As Long, j As Long, lngUpperI As Long, lngUpperJ As Long,
intLoweri As Integer, intLowerj As Integer, arrOut() As Variant
lngUpperI = UBound(arrIn, 1)
lngUpperJ = UBound(arrIn, 2)
intLoweri = LBound(arrIn, 1)
intLowerj = LBound(arrIn, 2)
ReDim arrOut(intLowerj To lngUpperJ, intLoweri To lngUpperI)
For i = intLoweri To lngUpperI
For j = intLowerj To lngUpperJ
arrOut(j, i) = arrIn(i, j)
Next
Next
Set arrIn = Nothing
TransposeArray = arrOut
End Function
The function usually works fine, but it generates an out of memory error
message on a 190,000 by 4 2d array. I presume that is because the function
is creating a new array, arrOut, that's as big as the incoming array, arrIn.
Does anyone know how to break down such a function into digestible bits, so
that it doesn't run out of memory? The worksheet function
Application.Transpose is not an option, as it generates an error message
after about 64,000 rows.
Thanks,
Wayne C.