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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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