Macro issues - trying to get an array to a column
Not really. The numbers were only meant to indicate the order I want them
in. The script I showed gives me stacked columns (col 1, then col 2, then
col 3). I want to have the rows stacked (row 1, row 2, then row 3).
I like this script, and I would imagine it's not a terribly complex edit to
get it to do what I want, but I can't get it edited correctly.
Thanks for any advice.
- V
"Dennis Tucker" wrote:
So you have a 2 dimensional array with unsorted values. You want it
converted to a 1 dimensional array that is sorted into ascending order.
I would probably dump the 2 dimensional array, element by element, into a
open column in Excel. Then use the sort ascending function on the column.
The create a 1 dimensional array and fill it with the sorted column.
Dennis
"valkyrie" wrote in message
...
I found a great macro I want to use to convert an array to a column. This
one takes an array like so:
1 2 3
4 5 6
and makes it
1
4
2
5
3
6
But I need
1
2
3
4
5
6
Can anyone help me edit it? I can't get it to work for the life of me.
Thanks!
Sub Matrix2Column()
Dim v As Variant
Dim nCol As Long
Dim nRow As Long
Dim rOut As Range
Dim iCol As Long
On Error Resume Next
v = Application.InputBox("Select range to copy", Type:=8).Value
If IsEmpty(v) Then Exit Sub
nRow = UBound(v, 1)
nCol = UBound(v, 2)
Set rOut = Application.InputBox("Select destination",
Type:=8).Resize(nRow, 1)
If rOut Is Nothing Then Exit Sub
For iCol = 1 To nCol
rOut.Value = WorksheetFunction.Index(v, 0, iCol)
Set rOut = rOut.Offset(nRow)
Next iCol
End Sub
|