Hlookup 2nd instance trouble

janderson055

New Member
Joined
Feb 7, 2012
Messages
30
I'm fairly new to using excel and have been trying to create a simple spreadsheet that keeps track of scores and automatically displays the names of the players in descending order. Anyway I have gotten to the point of using hookup to match a value and return that players name. But when two players have the same score it will only return the first found value. I sort the number scores using a LARGE function and it works great. Then I use something like this =HLOOKUP(Y2,B27:K28,2,FALSE) to match that value with the players name. Any suggestions on how to return the other players name when the scores are the same?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I'm fairly new to using excel and have been trying to create a simple spreadsheet that keeps track of scores and automatically displays the names of the players in descending order. Anyway I have gotten to the point of using hookup to match a value and return that players name. But when two players have the same score it will only return the first found value. I sort the number scores using a LARGE function and it works great. Then I use something like this =HLOOKUP(Y2,B27:K28,2,FALSE) to match that value with the players name. Any suggestions on how to return the other players name when the scores are the same?
Can you post some sample data so we can see what you're looking for?

I understand what you want to do but need to see how the data is setup to be able to make a suggestion.
 
Upvote 0
screen-capture.jpg
 
Upvote 0
OK, let's assume you have the scores listed starting in Y2 in descending order.

Book1
YZ
22150Player5
31800Player8
41700Player4
51550Player10
61300Player7
71300Player9
81100Player6
91000Player3
10800Player2
11700Player1
Sheet1

Enter this array formula** in Z2 and copy down as needed:

=INDEX($28:$28,SMALL(IF(B$27:K$27=Y2,COLUMN(B27:K27)),COUNTIF(Y$2:Y2,Y2)))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.
 
Upvote 0
No problem. I was also just wondering how that function works. I've used the IF and COUNTIF functions before, but never used the INDEX function before. If it isn't too much trouble can you please explain it a bit to me so I can use it later if need be. Thanks.
 
Upvote 0
No problem. I was also just wondering how that function works. I've used the IF and COUNTIF functions before, but never used the INDEX function before. If it isn't too much trouble can you please explain it a bit to me so I can use it later if need be. Thanks.
Let's look at this smaller example:

Book1
ABCDEF
1NamePlayer1Player2Player3Player4Player5
2Score100200100300200
Sheet1

Book1
AB
5ScoreName
6300Player4
7200Player2
8200Player5
9100Player1
10100Player3
Sheet1

This array formula** entered in B6 and copied down:

=INDEX($1:$1,SMALL(IF(B$2:F$2=A6,COLUMN(B2:F2)),COUNTIF(A$6:A6,A6)))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.

Here's how that formula works...

Look in this range (row 1) for the data we want to extract:

INDEX($1:$1

Each cell that is indexed is stored as a relative position. The positions start from 1 to the total number of cells in the indexed range. Depending on what version of Excel you're using if we index all of row 1 then the positions are:

In Excel 2007 and later: 1 to 16384

In Excel 2003 and earlier: 1 to 256

A1 = position 1
B1 = position 2
C1 = position 3
D1 = position 4
etc
etc

If we index the range D1:G1 then:

D1 = position 1
E1 = position 2
F1 = position 3
G1 = position 4

Now we need to tell the INDEX function we want to extract the data from the cells (positions) that meet a certain condition. In this case the condition is the player names that correspond to the nth largest numeric value from the range B2:F2.

We have the numeric values (scores) listed in descending order starting in cell A6.

We use this expression to return an array of the column numbers of the cell(s) that hold the nth largest score. If a cell does not contain the score we're looking for then the expression returns FALSE.

IF(B$2:F$2=A6,COLUMN(B2:F2))

For A6 (score 300) the array would look like this:

{FALSE,FALSE,FALSE,5,FALSE}

That tells us the score 300 was found in column number 5.

This array is passed to the SMALL function:

SMALL({FALSE,FALSE,FALSE,5,FALSE},

Then we have to tell the SMALL function which numeric value to pass to the INDEX function to exctract the data we want. We do that with the COUNTIF function.

When a score is unique then there will only be 1 column number in the array but when there are duplicate scores then there will be multiple column numbers in the array. For example, for score 200 the array would look like this:

{FALSE,3,FALSE,FALSE,6}

As the formula is entered and copied down the COUNTIF function will return the count of how many times the score appears in the range. We use this count to pass the nth smallest column number from the array to the INDEX function as the position number for the data we want to extract.

So, for A6 (score 300):

=INDEX($1:$1,SMALL({FALSE,FALSE,FALSE,5,FALSE},1))
=INDEX($1:$1,5)

Return the value from positon 5 of the indexed range (row 1). Positon 5 = cell E1 = Player 4.

For A7 (score 200):

=INDEX($1:$1,SMALL({FALSE,3,FALSE,FALSE,6},1))
=INDEX($1:$1,3)

Return the value from positon 3 of the indexed range (row 1). Positon 3 = cell C1 = Player 2.

For A8 (score 200 duplicate):

=INDEX($1:$1,SMALL({FALSE,3,FALSE,FALSE,6},2))
=INDEX($1:$1,6)

Return the value from positon 6 of the indexed range (row 1). Positon 6 = cell F1 = Player 5.

etc
etc
etc
 
Upvote 0

Forum statistics

Threads
1,215,554
Messages
6,125,487
Members
449,233
Latest member
Deardevil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top