Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
lbabli
 
Posts: n/a
Default Sort multiple rows by data in certain columns


I want to sort only certain columns (or cells) in a row as follows:

Unsorted...
A B C D E
1 Label3 1 3 4 2
2 Label2 4 1 16 8
3 Label4 2 9 1 6

Desired Sort of cells in columns B, C, D & E...sorting left to
right...
A B C D E
1 Label3 1 2 3 4
2 Label2 1 4 8 16
3 Label4 1 2 6 9

Any idea how this can be done?

Thank you


--
lbabli


------------------------------------------------------------------------
lbabli's Profile: http://www.excelforum.com/member.php...fo&userid=3952
View this thread: http://www.excelforum.com/showthread...hreadid=480196

  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default Sort multiple rows by data in certain columns

If you select B2:E2, you can use Data|sort and click on the Options button.

From there, you can specify that you want to sort by rows.

In code:

Option Explicit
Sub testme01()

Dim myRng As Range
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim wks As Worksheet

Set wks = Worksheets("sheet1")

With wks
FirstRow = 2 'headers in row 1??
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
Set myRng = .Range(.Cells(iRow, "B"), _
.Cells(iRow, .Columns.Count).End(xlToLeft))
myRng.Sort key1:=myRng.Cells(1), order1:=xlAscending, _
Header:=xlNo, Orientation:=xlLeftToRight
Next iRow
End With
End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
lbabli wrote:

I want to sort only certain columns (or cells) in a row as follows:

Unsorted...
A B C D E
1 Label3 1 3 4 2
2 Label2 4 1 16 8
3 Label4 2 9 1 6

Desired Sort of cells in columns B, C, D & E...sorting left to
right...
A B C D E
1 Label3 1 2 3 4
2 Label2 1 4 8 16
3 Label4 1 2 6 9

Any idea how this can be done?

Thank you

--
lbabli

------------------------------------------------------------------------
lbabli's Profile: http://www.excelforum.com/member.php...fo&userid=3952
View this thread: http://www.excelforum.com/showthread...hreadid=480196


--

Dave Peterson
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
sorting data across multiple columns Spiderman Excel Discussion (Misc queries) 2 October 6th 05 11:55 PM
Help PLEASE! Not sure what answer is: Match? Index? Other? baz Excel Worksheet Functions 7 September 3rd 05 03:47 PM
sharing rows of data across multiple worksheets within a workbook deedle93 Excel Worksheet Functions 2 August 18th 05 01:24 AM
Select rows of data in a worksheet on one criteria in multiple co MrSkoot99 Excel Worksheet Functions 5 July 11th 05 01:48 PM
Sort with multiple header rows Suzy Greblo Excel Discussion (Misc queries) 3 June 6th 05 10:50 PM


All times are GMT +1. The time now is 10:30 PM.

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

About Us

"It's about Microsoft Excel"