Thread: Sorting Rows
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Sorting Rows

Steve

Here is a Tom Ogilvy macro that sorts multiple rows.

Sub SortRows()
Dim r As Long
Dim lrow As Long

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lrow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row

'Make the r = 3 or whatever the first row of data you want to sort on is.
'The Cells(r, 2) means your data starts in Col 2 or Col B - adjust as
'necessary
'The resize(1, 4) expands the range to 1 cell deep by 4 cells wide

For r = 3 To lrow
With Cells(r, 2).Resize(1, 4)
.Sort Key1:=Cells(r, 1), Order1:=xlAscending, Header:=xlGuess, _
Orientation:=xlLeftToRight, DataOption1:=xlSortNormal
End With
Next r

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub


Gord Dibben MS Excel MVP

On Thu, 5 Oct 2006 20:18:55 +0100, Steve F
wrote:


I want to sort multiple rows, but seem to only be able to do one at a
time. I know that to sort multiple columns, I can highlight as many
columns as I want and then select A to Z on the Toolbar. But this
doesn't seem to be the case for sorting rows. In terms of sorting rows,
the only thing I can seem to do is to go into
Data--Sort--Options--Select Left to Right. I can then sort a single
row, and from this window it looks like I may--although I haven't
figured out how to get it to work--be able to sort three rows, but I
cannot tell how I might be able to sort more than three rows. For
instance, suppose I have the following data

3, 2, 1
6, 5, 4
98, 97, 96
33, 32, 21

I want to be able to select all of these rows and quickly sort them as
follows:

1, 2, 3
4, 5, 6
96, 97, 98
21, 32, 33

Thank you