Extracting data with VLOOKUP. How to handle duplicates?

jakemelon

Board Regular
Joined
Mar 14, 2003
Messages
76
VLOOKUP only allows you to look up the first occurence of data. What if the first one is not the one I want to extract?

For example:


Name | Age | IQ |
--------------------------------
Bob 15 100
Mary 20 96
Bob 7 110


=VLOOKUP("Bob",A2:C4,3)

I am using VLOOKUP to find BOB and extract his IQ. But VLOOKUP will find the first instance of BOB and return 100 as the result.

I need it to show me the BOB #2 IQ because he is less than 10 years old. I'd like the result to be "110"

Sorry about this lame illustration, does it make sense as to what I am looking for? how would I accomplish this task?

Jake
 
dwelleronthethreshold! I was able to create a UDF which worked for me and handled the duplicate values nicely. See below for code.
Code:
[FONT=courier new]Public Function CustomVLookUp(VL, Table As Range, Col, Inst)[/FONT]
[FONT=courier new]    On Error GoTo x[/FONT]
[FONT=courier new]    [/FONT]
[FONT=courier new]    Set SearchCol = Table.Columns(1)[/FONT]
[FONT=courier new]    [/FONT]
[FONT=courier new]    If Abs(Int(Inst)) <> Inst Or Inst > _[/FONT]
[FONT=courier new]    Application.CountIf(SearchCol, VL) Or Inst = 0 Then GoTo x[/FONT]
[FONT=courier new]    [/FONT]
[FONT=courier new]    Set mtch = SearchCol.Find(VL, LookIn:=xlValues)[/FONT]
[FONT=courier new]    For i = 1 To (Inst - 1)[/FONT]
[FONT=courier new]        Set mtch = SearchCol.Find(VL, After:=mtch, LookIn:=xlValues)[/FONT]
[FONT=courier new]    Next[/FONT]
[FONT=courier new]    [/FONT]
[FONT=courier new]    CustomVLookUp = mtch.Offset(0, Col - 1).Value[/FONT]
[FONT=courier new]    [/FONT]
[FONT=courier new]    Exit Function[/FONT]
[FONT=courier new]    [/FONT]
[FONT=courier new]x:  CustomVLookUp = ""[/FONT]
[FONT=courier new]End Function[/FONT]
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Upvote 0

Forum statistics

Threads
1,215,379
Messages
6,124,610
Members
449,174
Latest member
ExcelfromGermany

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