Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort selected range J.W. Aldridge Excel Programming 4 March 20th 09 05:41 PM
delete row and 3 rows below by range selected Corey Excel Programming 2 November 28th 06 08:14 AM
formula to sort a range so that it matches the exact rows of a column that is outside that range? steveo Excel Discussion (Misc queries) 1 June 18th 06 02:05 AM
excel - sort, selected rows?? [email protected] Excel Worksheet Functions 2 December 24th 05 05:23 PM
I want to sort selected cells in Excel, not entire rows. Aeryn635 Excel Discussion (Misc queries) 1 June 1st 05 07:58 PM


All times are GMT +1. The time now is 05:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"