Example: I have N columns each with X entires.
I want to be able to highlight (select) the range and have it sort each INDIVIDUAL column. (Ascending or desending would be a nice choice as would rows but I think I can figure that out once I have the basics)
So if I selct the following (and run the macro with this range selected.
The output would be:
I tried the record macro thing technique but it keeps entering in range values ("A2"), etc.
And I want to be able to select the ranges.
I tried this to no avail.
Sub SortMacro()
Dim A As Range
Dim B As Range
Set A = Application.Selection
NumColumns = A.Columns.Count
NumRows = A.Rows.Count
For N = 1 To NumColumns
Set B = Range(A.Cells(1, N), A.Cells(NumRows, N))
' Now sort B
' Listed as comment because it doesn't work. But here is what I'm trying to start with and getting errors.
'Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
' OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
' DataOption1:=xlSortNormal
' It seems B is now a value not a specified range??
Next N
End Sub
I promise I looked through the other 100 or so sorting threads but I don't see where this was addressed.
Thanks in advance for any help.
I want to be able to highlight (select) the range and have it sort each INDIVIDUAL column. (Ascending or desending would be a nice choice as would rows but I think I can figure that out once I have the basics)
Code:
5 52
425 2
45 4
45 3
54 5
So if I selct the following (and run the macro with this range selected.
The output would be:
Code:
5 2
45 3
45 4
54 5
425 52
I tried the record macro thing technique but it keeps entering in range values ("A2"), etc.
And I want to be able to select the ranges.
I tried this to no avail.
Sub SortMacro()
Dim A As Range
Dim B As Range
Set A = Application.Selection
NumColumns = A.Columns.Count
NumRows = A.Rows.Count
For N = 1 To NumColumns
Set B = Range(A.Cells(1, N), A.Cells(NumRows, N))
' Now sort B
' Listed as comment because it doesn't work. But here is what I'm trying to start with and getting errors.
'Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
' OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
' DataOption1:=xlSortNormal
' It seems B is now a value not a specified range??
Next N
End Sub
I promise I looked through the other 100 or so sorting threads but I don't see where this was addressed.
Thanks in advance for any help.