Vlookup with 2 or more lookup criteria and return multiple matches in excel
In previous posts I provided formulas on how to lookup one value in a list and return multiple matches.
- Using array formula to look up multiple values in a list
- How to return multiple values using vlookup in excel
- Search for multiple text strings in multiple cells in excel
Now I´ll show you how to lookup two or more values in a list and return (if possible) multiple matches.
Array formula in B13:
copied down as far as needed.
Array formula in B13 without named ranges:
copied down as far as needed.
I have to admit that I am not using Vlookup at all in this array formula. Vlookup looks for a value in the leftmost column of a table, and then returns a value in the same row from a column you specify. The column you specify is bolded in the above array formula.
Here is an alternative array formula:
This formula is easier to understand but what if the number of lookup values increases to let´s say 15 or more. The alternative array formula increases in size to this:
=INDEX($C$2:$C$6, SMALL(IF(($B$9=$B$2:$B$6)+($B$10=$B$2:$B$6)+($B$11=$B$2:$B$6)+($B$12=$B$2:$B$6)+($B$13=$B$2:$B$6)+($B$14=$B$2:$B$6)+($B$15=$B$2:$B$6)+($B$16=$B$2:$B$6)+($B$17=$B$2:$B$6)+($B$18=$B$2:$B$6)+($B$19=$B$2:$B$6)+($B$20=$B$2:$B$6)+($B$21=$B$2:$B$6)+($B$22=$B$2:$B$6)+($B$23=$B$2:$B$6), ROW($B$2:$B$6)-1, ""), ROW(A1))) + CTRL + SHIFT + ENTER.
The first array formula is easier to customize if more lookup values are added. It is also smaller in size when many lookup values are used. The first array formula is not case-sensitive. To create a case-sensitive formula use FIND instead of SEARCH.
Named ranges
tbl (B2:C6)
search_tbl (B9:B10)
What is named ranges?
How to increase the number of search strings
Change the named range search_tbl.
How the array formula works (without named ranges) in cell B13
=INDEX($C$2:$C$6, SMALL(IF(COUNTIF($B$9:$B$10,$B$2:$B$6), ROW($B$2:$C$6)-MIN(ROW($B$2:$C$6))+1), ROW(A1)))
Step 1 - Filter values
=INDEX($C$2:$C$6, SMALL(IF(COUNTIF($B$9:$B$10,$B$2:$B$6), ROW($B$2:$C$6)-MIN(ROW($B$2:$C$6))+1), ROW(A1)))
COUNTIF(range,criteria)
Counts the number of cells within a range that meet the given condition.
COUNTIF($B$9:$B$10,$B$2:$B$6)
becomes
COUNTIF({"Pen";"Paper"},{"Pen";"Eraser";"Paper";"Pen";"Paper clip"})
and returns {1;0;1;1;0}
Step 2 - Convert Boolean array into row numbers
=INDEX($C$2:$C$6, SMALL(IF(COUNTIF($B$9:$B$10,$B$2:$B$6), ROW($B$2:$C$6)-MIN(ROW($B$2:$C$6))+1), ROW(A1)))
IF(COUNTIF($B$9:$B$10,$B$2:$B$6), ROW($B$2:$C$6)-MIN(ROW($B$2:$C$6))+1)
becomes
IF({1;0;1;1;0}, ROW($B$2:$C$6)-MIN(ROW($B$2:$C$6))+1)
becomes
IF({1;0;1;1;0}, {2;3;4;5;6})-MIN({2;3;4;5;6}))+1)
becomes
IF({1;0;1;1;0}, {2;3;4;5;6})-2+1)
becomes
IF({1;0;1;1;0}, {1;2;3;4;5})
and returns {1;FALSE;3;4;FALSE}.
Step 3 - Returns the k-th smallest row number
=INDEX($C$2:$C$6, SMALL(IF(COUNTIF($B$9:$B$10,$B$2:$B$6), ROW($B$2:$C$6)-MIN(ROW($B$2:$C$6))+1), ROW(A1)))
SMALL(IF(COUNTIF($B$9:$B$10,$B$2:$B$6), ROW($B$2:$C$6)-MIN(ROW($B$2:$C$6))+1), ROW(A1))
becomes
SMALL({1;FALSE;3;4;FALSE}, ROW(A1))
becomes
SMALL({1;FALSE;3;4;FALSE}, 1)
returns 1.
Step 4 - Returns a value of the cell at the intersection of a particular row and column
=INDEX($C$2:$C$6, SMALL(IF(COUNTIF($B$9:$B$10,$B$2:$B$6), ROW($B$2:$C$6)-MIN(ROW($B$2:$C$6))+1), ROW(A1)))
becomes
=INDEX($C$2:$C$6, 1)
becomes
=INDEX({1.5;2;1.5;1.7;3}, 1)
and returns 1.5 in cell B13.
Download excel example file
Vlookup-with-two-search-criteria-and-return-multiple-matches.xls
(Excel 97-2003 Workbook *.xls)
Functions in this article:
IF(logical_test;[value_if:true];[value_if_false])
Checks whether a condition is met, and returns one value if TRUE, and another value if FALSE
INDEX(array,row_num,[column_num])
Returns a value or reference of the cell at the intersection of a particular row and column, in a given range
COUNTIF(range,criteria)
Counts the number of cells within a range that meet the given condition
ROW(reference) Returns the rownumber of a reference
SMALL(array,k) Returns the k-th smallest number in this data set.
Recommended articles
Check out these posts and learn more about vlookup.
- How to return multiple values using vlookup
- Vlookup with 2 or more lookup criteria and return multiple matches in excel
- Using array formula to look up multiple values in a list
- Search for multiple text strings in multiple cells in excel
- Vlookup – Return multiple unique distinct values in excel
- Fuzzy vlookup (excel array formula)
- Lookup using two criteria in excel
- Search case sensitive and return multiple values in excel
- Vlookup a range in excel
- Vlookup with multiple matches returns a different value in excel
- Vlookup of three columns to pull a single record
Related posts:
Lookup values in a range using two or more criteria and return multiple matches in excel
Lookup values in a range using two or more criteria and return multiple matches in excel, part 2
Lookup a value in a list and return multiple matches in excel
Vlookup with multiple matches returns a different value in excel



















Oscar, on the first formula, any reason why you have multiplied with ))*(SEARCH(search_tbl, TRANSPOSE(INDEX(tbl, , 1, 1))))? As this step looks redunant?
Thanks!
I forgot this post.
Using countif() instead of search() reduces formula size.
The reason why I multiplied two search() in the first place, was to remove any cells that contained the search criteria, I was looking for exact matches.
Does anyone know how to do a vlookup of three columns to pull a single record?
Andy,
Can you elaborate?
Match a single criterion in any of three columns?
Match three different criteria in each column?
Match any of three different criteria in any column?
Andy,
See this post: http://www.get-digital-help.com/2010/01/10/vlookup-of-three-columns-to-pull-a-single-record/
Hello Oscar,
I tried the formulas couple times and they do not work. I want Vlookup to add all the group A $ and placed on Sheet2 group A. For example:
Sheet1:
GRP $
A 2
A 2
A 2
B 3
B 3
B 3
C 4
C 4
C 4
Sheet2:
Grp $
A ???
B ???
C ???
if I add manually group A total is $6 and B total is $9 and C total is $12.
Thank you very much,
newsuteuser2011
newsiteuser2011,
or create a pivot table on sheet2
Oscar, what happen if I need to use IF(ISERROR(Vlookup)) and the datas are pretty big for every month. Is there a way to request Vlookup to pickup more than the first data?
Thank you,
Newsiteuser2011
newsiteuser2011,
Try the formula in this post: How to return multiple values using vlookup in excel
I have a large database with 40 columns, I wish to extract a few column data into separate sheet for printing. The goal is actually a male name list and a female name list with another criteria from a column that is confirmed. Which page shows the examples?
Thank you
Alex Chiok
Alex Chiok,
Excel tables are easy and fast!
http://office.microsoft.com/en-us/excel-help/overview-of-excel-tables-HA010048546.aspx
Oscar,
I am using this formula and have found that it does not produce all of the results from the data file.
My data sheet contains:
Column (A) - Account Number
Column (B) - Date
Column (C) - Notes
There are 1 - 15 instances of the account number in Column (A).
The instances may be on different or the same day (date) in column (B).
The notes in Column (C) are all different.
The results being returned are limited to only two rows per date.
So if I have 5 Notes on 01/01/2012....the results are only returning 2 of them...it appears to be the two middle rows.
Can you help.
Thanks for the great formula!!
I should have included the formula mentioned above just to be clear:
=INDEX(COMMENTS!$I$2:$I$15000, SMALL(IF((GET_COMMENTS!$E$3=COMMENTS!$A$2:$A$15000)*(GET_COMMENTS!$E$3=COMMENTS!$A$2:$A$15000), ROW(COMMENTS!$A$2:$A$15000)-MIN(ROW(COMMENTS!$A$2:$A$15000))+1, ""), ROW(A1)))
Oscar,
Nevermind, I'm loosing it. Too many hours in front of a spreadsheet.
beth,
Download file:
beth.xlsx
Thanks, This is so useful!!
your explanation makes wonders happen.
But can I ask how do you learn this kind of stuff?
Richard,
Thanks!!
But can I ask how do you learn this kind of stuff?
Inspired by others. Trial and error. As far as I know there are no array formula books out there.
Hi Oscar,
On the above example, is there any way I can tranpose the results against the original search ref. as oppose to the vertical lists so that I don't have just a long string of values. That way I can quickly match the corresponding values with the original search ref.
Hope that makes sense!
Emma,
I believe this post is what you are looking for: http://www.get-digital-help.com/2009/10/25/how-to-return-multiple-values-using-vlookup-in-excel/#horizont
Thanks for the references to excel on your website, they have been very helpful. I am trying to alter your formula without any avail.
I am trying to perform a lookup with two criteria and return multiple values which matches the search. I have two worksheets on named Source Data and Available Filler by Page. Source Data has four columns: Book #, Filler Name, Page #, Size
I neeed to lookup the book # and corresponding size to return the page numbers which are available for them horizontally, but i have only been able to return only one criteria because I am not using the AND function correctly inside the IF statement. Here is the formula I have been using:
=IFERROR(INDEX('Source Data'!$C$2:$C$10000,SMALL(IF(AND('Available Fillers by Page'!$B$7='Source Data'!$A$2:$A$10000,'Source Data'!$D$2:$D$10000='Available Fillers by Page'!$E$8),ROW('Source Data'!$A$2:$A$10000)-MIN(ROW('Source Data'!$A$2:$A$10000))+1,""),COLUMN(A1))),"")
Any assistance would be great. Thank you in advance.
I found a formula on another page but how do I get the formula to list the values horizontally. Here is the new formula I used:
=IFERROR(INDEX('Source Data'!$C$2:$C$10000, SMALL(IF(('Available Fillers by Page'!$B$7='Source Data'!$A$2:$A$10000)*('Available Fillers by Page'!$E8='Source Data'!$D$2:$D$10000), ROW('Source Data'!$C$2:$C$10000)-MIN(ROW('Source Data'!$C$2:$C$10000))+1), COLUMN(1:1))),"NFA")
This formula only lists the first value when copied horizontally.
Nevermind my last post, I got it. Once again thank you for the website. I will leep it as a favorite because I know I will be needing it another time.
Dominica Smith,
I am happy you found what you were looking for.