## 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**

### Mod

The Mod function returns the remainder after a number is divided by divisor. The Mod function is short for the Modulo operation (link to wikipedia). MOD(number, divisor) Number - The number for which you want to find the remainder. Divisor - The […]

Denisa asks: I have a problem and i cant figure it out, even if i'm seraching for 2 days. I have the following situation: A1, B1, C1, D1, E1, F1 where A1 = nick b1 = 10 c1 = zack […]

Can someone explain to me why this happens? This example is working. FREQUENCY function returns {2; 1; 1}. 2 values (0.1 and 0.2) are equal to or less than 0.2. 1 value (0.3) is larger than 0.2 and equal or smaller than 0.3. 1 […]

### Sort values

Table of Contents Sort a column using array formula Two columns sorting by the second column Sort alphanumeric values I am inspired once again by the article Sorting Text in Excel using Formulas at Pointy haired Dilbert. In Chandoo´s article […]

Question: How do I create a drop down list with unique distinct alphabetically sorted values? Answer: Table of contents Sort values using array formula Sort values using vba Sort values using array formula Array formula in cell B2 =INDEX(List, MATCH(0, […]

In this post I am going to show how to create a new sheet for each airplane using vba. The macro copies airplane and model values into each new sheet. Before: After: The Code Download excel tutorial file Remember to […]

### 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))