Sort by Rows for a selected range

  • Thread starter Thread starter Rose
  • Start date Start date
R

Rose

I understand that simple sorting by rows can be done by using data>sort>left
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.
 
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
 
Back
Top