T
TheVisionThing
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.
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.