Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sort by Rows for a selected range
I understand that simple sorting by rows can be done by using datasortleft
to right; however this poses the problem that only Level 1 is sorted even if there is a highlighted range. Can you help me in creating a code wherein after Level1, it jumps to Level 2 up to the last row? I'm relatively new at macro and I'm failing miserably. I tried doing For and Next code. The data I want to sort in ascending order are in Columns B:G. Appreciate any help. ----------------------------------------------------------------------------- Less Spam Better enjoyable experience Visit : news://spacesst.com |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sort by Rows for a selected range
Sub SortRows() LastRow = Range("A" & Rows.Count).End(xlUp).Row For RowCount = 1 To LastRow LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Column Range(Cells(RowCount, "A"), Cells(RowCount, LastCol)).Sort _ Key1:=Range("A" & RowCount), _ Order1:=xlAscending, _ Header:=xlNo, _ Orientation:=xlLeftToRight Next RowCount End Sub "Rose" wrote: I understand that simple sorting by rows can be done by using datasortleft to right; however this poses the problem that only Level 1 is sorted even if there is a highlighted range. Can you help me in creating a code wherein after Level1, it jumps to Level 2 up to the last row? I'm relatively new at macro and I'm failing miserably. I tried doing For and Next code. The data I want to sort in ascending order are in Columns B:G. Appreciate any help. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sort by Rows for a selected range
I did some modifications, but your code made it possible. Thanks "Joel" wrote: Sub SortRows() LastRow = Range("A" & Rows.Count).End(xlUp).Row For RowCount = 1 To LastRow LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Column Range(Cells(RowCount, "A"), Cells(RowCount, LastCol)).Sort _ Key1:=Range("A" & RowCount), _ Order1:=xlAscending, _ Header:=xlNo, _ Orientation:=xlLeftToRight Next RowCount End Sub "Rose" wrote: I understand that simple sorting by rows can be done by using datasortleft to right; however this poses the problem that only Level 1 is sorted even if there is a highlighted range. Can you help me in creating a code wherein after Level1, it jumps to Level 2 up to the last row? I'm relatively new at macro and I'm failing miserably. I tried doing For and Next code. The data I want to sort in ascending order are in Columns B:G. Appreciate any help. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Sort selected range | Excel Programming | |||
delete row and 3 rows below by range selected | Excel Programming | |||
formula to sort a range so that it matches the exact rows of a column that is outside that range? | Excel Discussion (Misc queries) | |||
excel - sort, selected rows?? | Excel Worksheet Functions | |||
I want to sort selected cells in Excel, not entire rows. | Excel Discussion (Misc queries) |