E
ExcelMonkey
Been trying to use Alan Beban's Column Vector routine to extract the column
vector of a 2-D array. Not sure if I understand what its doing. The code
below populates a 2-D array (FirstArray)with random number then prints them
to the immediate window. Then I use Alan's Column Vector Array to create a
new array (SecondArray) which has only the first column of data from the
FirstArray. When I check the first two column items in the FirstArray, you
can see below they match the 1st column of the array printout (0,0 and 0,1).
I expected to see a 1-D array as a result of the Alan’s function . Secondly,
given that its still a 2-D array, it appears that the columns values from the
first array are in different element addresses (0,1 and 1,1 compared to 0,0
and 0,1). I have not posted Alan’s code for the function. Although I think
I can as he freely gives it away over the internet.
Option Base 0
Sub Main()
Dim FirstArray() As Variant
Dim SecondArray() As Variant
Dim X As Double
Dim Y As Double
ReDim FirstArray(0 To 1, 0 To 3)
For X = 0 To UBound(FirstArray, 1)
For Y = 0 To UBound(FirstArray, 2)
FirstArray(X, Y) = Round(Rnd() * 1000, 0)
Next
Debug.Print FirstArray(X, 0), FirstArray(X, 1), FirstArray(X, 2),
FirstArray(X, 3)
Next
SecondArray = ColumnVector(FirstArray, 0) ‘This is Alan’s Function
End Sub
IMMEDIATE WINDOW
706 533 580 290
302 775 14 761
?FirstArray(0,0)
706
?FirstArray(1,0)
302
?SecondArray(0,1)
706
?SecondArray(1,1)
302
vector of a 2-D array. Not sure if I understand what its doing. The code
below populates a 2-D array (FirstArray)with random number then prints them
to the immediate window. Then I use Alan's Column Vector Array to create a
new array (SecondArray) which has only the first column of data from the
FirstArray. When I check the first two column items in the FirstArray, you
can see below they match the 1st column of the array printout (0,0 and 0,1).
I expected to see a 1-D array as a result of the Alan’s function . Secondly,
given that its still a 2-D array, it appears that the columns values from the
first array are in different element addresses (0,1 and 1,1 compared to 0,0
and 0,1). I have not posted Alan’s code for the function. Although I think
I can as he freely gives it away over the internet.
Option Base 0
Sub Main()
Dim FirstArray() As Variant
Dim SecondArray() As Variant
Dim X As Double
Dim Y As Double
ReDim FirstArray(0 To 1, 0 To 3)
For X = 0 To UBound(FirstArray, 1)
For Y = 0 To UBound(FirstArray, 2)
FirstArray(X, Y) = Round(Rnd() * 1000, 0)
Next
Debug.Print FirstArray(X, 0), FirstArray(X, 1), FirstArray(X, 2),
FirstArray(X, 3)
Next
SecondArray = ColumnVector(FirstArray, 0) ‘This is Alan’s Function
End Sub
IMMEDIATE WINDOW
706 533 580 290
302 775 14 761
?FirstArray(0,0)
706
?FirstArray(1,0)
302
?SecondArray(0,1)
706
?SecondArray(1,1)
302