franklin_m
New Member
- Joined
- Jun 16, 2013
- Messages
- 47
- Office Version
- 365
- Platform
- Windows
- MacOS
I'm continuing my effort to learn to use arrays. What I'd like to do is create one array, determine it's size, and then create a second array and dimension (or redimension) to a size that is a transpose of the first. In other words, if Array1 is 10 rows and 2 columns, I'd read UBound rows & columns of Array1 and create a second array that is 2 rows by 10 columns. I'm doing this so I don't screw up the math on complex data transformation that's running slowly due to size. I want to do the calcs inside arrays to speed things up.
So here's the code I thought would work, but when I run it againts a simple 12 row by 2 column set of data, it gives "Script out of range" and debugger hangs on line beginning "MonthValuesTX(j, i) ... "
I'm pretty sure it's something simple, but for the life of me I can't see it. Thanks.
So here's the code I thought would work, but when I run it againts a simple 12 row by 2 column set of data, it gives "Script out of range" and debugger hangs on line beginning "MonthValuesTX(j, i) ... "
I'm pretty sure it's something simple, but for the life of me I can't see it. Thanks.
VBA Code:
Sub ArrayTest_v1()
Dim MonthValues() As Variant
MonthValues = Worksheets("ArraySandbox").Range("A2:B13").Value
Dim RowsInArray As Long
Dim ColsInArray As Long
RowsInArray = UBound(MonthValues, 1)
ColsInArray = UBound(MonthValues, 2)
Dim MonthValuesTX() As Variant
ReDim MonthValues(ColsInArray, RowsInArray)
Dim i As Long
Dim j As Long
For i = 1 To RowsInArray
For j = 1 To ColsInArray
MonthValuesTX(j, i) = MonthValues(i, j)
Next j
Next i
End Sub