## Sort names by value

I have the following situation:

A1, B1, C1, D1, E1, F1

where

A1 = nick

b1 = 10

c1 = zack

d1 = 15

e1 - john

f1 = 13

what formula should i use to get them ordered counting the numbers but names still being asociated, like this:

a1 = zack

b1 = 15

c1 = john

d1 = 13

e1 = nick

f1 = 10

Formula in cell A3:

### Explaining formula

*Find n-th largest number in cell range and repeat every number*

ROUND(COLUMN(A1)*0.5,0)

becomes ROUND(1*0.5,0)

becomes ROUND(0.5,0)

and returns 1. Copy the formula to the next cell gives ROUND(COLUMN(B1)*0.5,0) and returns 1 again.

As you copy the formula to the left this sequence is created 1,1,2,2,3,3,4,4,5,5 and so on.

What happens if we combine the above with the LARGE function?

LARGE($A$1:$F$1,ROUND(COLUMN(A1)*0.5,0))

The LARGE function extracts the n-th largest number twice for every two cells. This allows us to return both the number and the corresponding name later on.

**Find position of the n-th largest number in cell range**

This formula is valid for cell A3, when you copy it to cell A4 the cell refs change. Check out blog post absolute and relative cell references and learn how to build smarter formulas.

MATCH(LARGE($A$1:$F$1,ROUND(COLUMN(A1)*0.5,0)),$A$1:$F$1,0)

becomes

MATCH(15,$A$1:$F$1,0)

and returns 4. Read more about MATCH function.

**Subtract one to get the corresponding name for every second cell.**

MATCH(LARGE($A$1:$F$1,ROUND(COLUMN(A1)*0.5,0)),$A$1:$F$1,0)-MOD(COLUMN(A1),2)

MOD(COLUMN(A1),2) returns 1,0,1,0,1, ... and so on as you copy the formula further to the right. This enables the formula to extract the name for every second cell.

More MOD examples: Learn how the MOD function works, Quotient, Mod and Int functions

**Return number or name**

=INDEX($A$1:$F$1,MATCH(LARGE($A$1:$F$1,ROUND(COLUMN(A1)*0.5,0)),$A$1:$F$1,0)-MOD(COLUMN(A1),2))

The INDEX function returns n-th largest number or corresponding name.

### Data vertically

This formula returns data vertically:

**Download excel *.xlsx**

### 7 Responses to “Sort names by value”

### Leave a Reply

**How to add a formula to your comment:**

<code>your formula</code>

**How to add VBA code to your comment:**

[vb 1="vbnet" language=","]

VBA code

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org

Add picture link to comment.

**Contact Oscar**

You can contact me through this webpage

Elegant solution!

Excellent job Oscar, and not for the first time.

I like your site.

Beautiful formula,

you're not even an array.

Thank you all!

David, you are right. You don't need to enter the formula as an array formula. I was wrong. Thanks for pointing that out.

By the way, substitute the LARGE function with the SMALL function to sort values in ascending order.

[…] ← Previous post - […]

By adding a small value like COLUMN($A$1:$F$1)/10000 we can handle ties(not array formula entered in A3):

=INDEX($A$1:$F$1,MATCH(AGGREGATE(14,6, $A$1:$F$1+COLUMN($A$1:$F$1)/10000,ROUND(COLUMN(A1)*0.5,0)),INDEX($A$1:$F$1+COLUMN($A$1:$F$1)/10000,,),0)-MOD(COLUMN(A1),2))