Sort every row

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have about a thousand rows of data (with 6 columns).
How can I quickly sort every row in ascending order?
 
Sub SortRows()
'Tom Ogilvy macro
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 = 1 whatever the first row of data you want to sort on is.
'The Cells(r, 1) means your data starts in Col 1 or Col A - adjust as
necessary
'The resize(1, 4) expands the range to 1 cell deep by 4 cells wide

For r = 1 To Lrow
With Cells(r, 2).Resize(1, 7)
.Sort Key1:=Cells(r, 2), 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
 
Back
Top