Hi there. I need to read some data from a worksheet range that could either be horizontal (x columns by 1 row) or vertical (1 column by x rows) into a variant array, then redim preserve it so that is longer or wider.
While I've cobbled together something, I don't really understand it:
I read at http://vbadud.blogspot.com/2007/12/array-dimensioning-in-visual-basic.html that if you use the Preserve keyword, you can resize only the last array dimension. Hence the application.transpose part of my code.
But I don't understand why I have to use use ReDim Preserve a(1, 1 To 50) for horizontal ranges and ReDim Preserve a(1 To 50) for vertical ranges. Does transposing a worksheet range do something funny to it that I'm not aware of, like turning it from a 2d to a 1d array?
While I've cobbled together something, I don't really understand it:
Code:
Public Function IncreaseRange(rngInput As Range)
Dim a
a = rngInput
If UBound(a, 2) > UBound(a, 1) Then
ReDim Preserve a(1, 1 To 50)
Else
a = Application.Transpose(rngInput)
ReDim Preserve a(1 To 50)
End If
IncreaseRange = a
End Function
I read at http://vbadud.blogspot.com/2007/12/array-dimensioning-in-visual-basic.html that if you use the Preserve keyword, you can resize only the last array dimension. Hence the application.transpose part of my code.
But I don't understand why I have to use use ReDim Preserve a(1, 1 To 50) for horizontal ranges and ReDim Preserve a(1 To 50) for vertical ranges. Does transposing a worksheet range do something funny to it that I'm not aware of, like turning it from a 2d to a 1d array?