# How to sort numbers?

#### excelos

##### Active Member
Hello

I have a row with numbers 1,5,5,5,4,4,3,3,0,1

How can I sort them so that they are ranked by ascending number and the most left is the first if more than two same values exist?
Also, how do I return the value that is second maximum and if more than one values, return the cell address of the second one, ie second from left?

Thanks!

### Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

#### oldbrewer

##### Board Regular
in a helper column put the number plus row number multiplied by .00000001
then sort using small function

or column number if your list is horizontal

#### AlKey

##### Active Member
Assuming the numbers are in cell A1

If you use Excel version 2010 or higher you can use AGGREGATE function
Enter formula in cell B1 and drag formula down
Code:
``[B]=AGGREGATE(15,6,--MID(SUBSTITUTE(A\$1,",",REPT(" ",99)),99*(COLUMN(A:Z)-1)+1,99),ROWS(A\$1:A1))[/B]``
Otherwise use array formula. **Must be entered with Ctrl+Shift+Enter key combination.
Code:
``[B]=SMALL(IFERROR(--MID(SUBSTITUTE(A\$1,",",REPT(" ",99)),99*(COLUMN(A:Z)-1)+1,99),""),ROWS(A\$1:A1))[/B]``

Last edited:

#### oldbrewer

##### Board Regular
 1,5,5,5,4,4,3,3,0,1 1 5 5 5 4 4 3 3 0 1 0 1 1 3 3 4 4 5 5 5 row 4 1 2 3 4 5 6 7 8 9 10 1.00000003 5 5 5 4 4 3 3 1.1E-07 1 row 18 formula giving the zero in row 4 =IF(SMALL(\$C\$18:\$L\$18,C17)<1,0,SMALL(\$C\$18:\$L\$18,C17)) formula giving the first number in row 18 =C3+COLUMN()*0.00000001

<colgroup><col span="2"><col><col span="13"></colgroup><tbody>
</tbody>

#### AlKey

##### Active Member
You did not mention that sorting should be in columns
Enter formula in B1 and drag across until you see blanks
For Excel 2010 and higher:
Code:
``[B]=IFERROR(AGGREGATE(15,6,--MID(SUBSTITUTE(\$A1,",",REPT(" ",99)),99*(COLUMN(1:1)-1)+1,99),COLUMNS(\$B:B)),"")[/B]``

For the Excel version 2007 and up use array formula
Code:
``[B]=IFERROR(SMALL(IFERROR(--MID(SUBSTITUTE(\$A1,",",REPT(" ",99)),99*(COLUMN(1:1)-1)+1,99),""),COLUMNS(\$B:B)),"")[/B]``

Last edited:

Replies
0
Views
42
Replies
5
Views
41
Replies
7
Views
47
Replies
12
Views
137
Replies
0
Views
71