Sort each line horizontally and separately

N

nils

I have a worksheet with 200 lines. I would like to sort each line
horizontally, so that the lowest number in each line is represented in column
A, and the second lowest number in column B and so on. Can this be done for
all the lines at the same time?


Before sorting
A B C
Line 1 2 1 7
Line 2 5 8 1

After sorting
A B C
Line 1 1 2 7
Line 2 1 5 8
 
M

Max

Assume your source data is running in A1:C1 down
In say, E1: =SMALL($A1:$C1,COLUMNS($A:A))
Copy across to G1, fill down as far as required to return desired results
Any good? hit the YES below
--
Max
Singapore
http://savefile.com/projects/236895
Downloads:27,000 Files:200 Subscribers:70
xdemechanik
 
G

Gord Dibben

Select the 200 rows then run this macro.

Edit to suit.

Sub SortRows()
'Tom Ogilvy macro
Dim r As Long
Dim lRow As Long

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lRow = ActiveSheet.Cells(Rows.Count, "A").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, 7) expands the range to 1 cell deep by 7 cells wide

For r = 1 To lRow
With Cells(r, 1).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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top