Sort by Rows for a selected range

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.
 
J

Joel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top