robpennington84 wrote:I wish there was another option in the VLOOKUP() function that deals with duplicate entries. Like, you could tell it you wanted the value for the nth instance of your search criteria in the range of cells. That would be sweet.
Hi Rob,
Here's an example of looking up a value corresponding to the nth occurrence.
The lookup value is selected from the A2 drop down.
The occurrence is selected from the B2 drop down.
The formula in C2...
=OFFSET($E$1;MATCH(A2&B2;$F$2:$F$20;0);0)
returns the column E value corresponding to the B2 occurrence of the A2 value in column D.
Helper 1 column with formula...
=D2&COUNTIF($D$2:D2;D2)
concatenates the current column D value with the count of that value from D2 down to the current row.
(I've changed from concatenating with a string of "a"s to simply the current count)
So, the MATCH function in the C2 formula looks down column F for the A2 value concatenated with the B2 value. For example if A2 = "Charisma" and B2 = 2 then MATCH(A2&B2;$F$2:$F$20;0) looks for "Charisma2" in $F$2:$F$20 and returns 9.
The OFFSET function in the C2 formula then starts in $E$1 and returns the value in the cell that is 9 rows down (E10), which is 16.
Helper 2 column with formula...
=IF(ROW(A1)>COUNTIF(D$2:D$20;$A$2);"";ROW(A1))
produces a list from 1 up to the count of the A2 value in column D followed by empty strings.
The Data Validity applied to B2 is the cell range defined by the formula...
OFFSET($Sheet1.$G$2;0;0;SUMPRODUCT($Sheet1.$G$2:$G$65536<>"");1)
which is all the cells in column G below G1 that are not blank.
Ken Johnson