![]() |
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 |
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. |
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. |
All times are GMT +1. The time now is 10:35 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com