ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Sort each line horizontally and separately (https://www.excelbanter.com/excel-worksheet-functions/243249-sort-each-line-horizontally-separately.html)

Nils

Sort each line horizontally and separately
 
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
--
Best regards

Nils

Max

Sort each line horizontally and separately
 
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
---
"nils" wrote:
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
--
Best regards

Nils


Gord Dibben

Sort each line horizontally and separately
 
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

On Mon, 21 Sep 2009 04:39:01 -0700, nils
wrote:

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




All times are GMT +1. The time now is 10:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com