Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]() 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
![]() |
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
sorting data across multiple columns | Excel Discussion (Misc queries) | |||
Help PLEASE! Not sure what answer is: Match? Index? Other? | Excel Worksheet Functions | |||
sharing rows of data across multiple worksheets within a workbook | Excel Worksheet Functions | |||
Select rows of data in a worksheet on one criteria in multiple co | Excel Worksheet Functions | |||
Sort with multiple header rows | Excel Discussion (Misc queries) |