Sorting data in rows
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, 1).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
Since you have 5 columns change the resize to 1 ,5 and to leave column A out of
the mix change r ,1 to r , 2
Gord Dibben MS Excel MVP
On Tue, 29 May 2007 09:32:00 -0700, LT_childrens
wrote:
thanks Mike, i tried that already, but because it asks which field to sort by
it will sort everything still by one row. Meaning, the first row will be
correct but the others will just move according to the first row. I need each
row to sort individually. Does that make sense?
"Mike H" wrote:
Try:-
Select your data.
Data|sort|options|sort left to right
Mike
"LT_childrens" wrote:
I probably should know how to do this but i can't figure it out. I have a
database with patient codes in up to 20 columns. I want each row to sort the
data that goes across the 20 columns. for example: (using numbers saved as
text)
PatA 1 5 4 3 2
PatB 5 4 1 6 7
PatC 8 7 3 2 1
Would look like:
PatA 1 2 3 4 5
PatB 1 4 5 6 7
PatC 1 2 3 7 8
|