The tutorial shows a few ways to Vlookup multiple matches in Excel based on one or more conditions and return multiple results in a column, row or single cell.
When using Microsoft Excel for data analysis, you may often find yourself in situations when you need to get all matching values for a specific id, name, email address or some other unique identifier. An immediate solution that comes to mind is using the Excel VLOOKUP function, but the problem is that it can only return a single match.
Vlookup for multiple values can be done via a combined use of several functions. If you are far from being an Excel expert, don't hurry to leave this page. I will do my best to explain the underlying logic so that even a novice could understand the formulas and adjust them for solving similar tasks. Even better, I will show you another possible solution that takes just a few mouse clicks and does not require any knowledge of Excel formulas at all!
How to do multiple Vlookup in Excel using a formula
As mentioned in the beginning of this tutorial, there is no way to make Excel VLOOKUP return multiple values. The task can be accomplished by using the following functions in an array formula:
- IF - evaluates the condition and returns one value if the condition is met, and another value if the condition is not met.
- SMALL - gets the k-th smallest value in the array.
- INDEX - returns an array element based on the row and column numbers you specify.
- ROW - returns the row number.
- COLUMN - returns the column number.
- IFERROR - traps errors.
Below you will find a few examples of such formulas.
Formula 1. Vlookup multiple matches and return results in a column
Let's say, you have the seller names in column A and the products they sold in column B, column A containing a few occurrences of each seller. Your goal is to get a list of all products sold by a given person. To have it done, please follow these steps:
- Enter a list of unique names in some empty row, in the same or another worksheet. In this example, the names are input in cells D2:G2:
Tip. To quickly get all different names in a list, you can use the UNIQUE function in Excel 365 or a more complex formula to extract distinct values in older versions.
- Under the first name, select a number of empty cells that is equal to or greater than the maximum number of possible matches, enter one of the following array formulas in the formula bar, and press Ctrl + Shift + Enter to complete it (in this case, you will be able to edit the formula only in the entire range where it's entered). Or, you can enter the formula in the first cell, hit Ctrl + Shift + Enter, and then drag the formula down to a few more cells (in this case, you will be able to edit the formula in each cell individually).
=IFERROR(INDEX($B$3:$B$13, SMALL(IF(D$2=$A$3:$A$13, ROW($B$3:$B$13)-2,""), ROW()-2)),"")
or
=IFERROR(INDEX($B$3:$B$13,SMALL(IF(D$2=$A$3:$A$13,ROW($A$3:$A$13)- MIN(ROW($A$3:$A$13))+1,""), ROW()-2)),"")
As you see, the 1st formula is a bit more compact, but the 2nd one is more universal and requires fewer modifications (we will elaborate more on the syntax and logic a bit further).
- Copy the formula to other columns. For this, select the range of cells where you've just entered the formula, and drag the fill handle (a small square at the lower right-hand corner of the selected range) to the right.
The result will look something similar to this:
How this formula works
This is an example of intermediate to advanced uses of Excel that implies basic knowledge of array formulas and Excel functions. Working from the inside out, here's what you do:
- IF function
At the core of the formula, you use the IF function to get the positions of all occurrences of the lookup value in the lookup range: IF(D$2=$A$3:$A$13, ROW($B$3:$B$13)-2,"")
IF compares the lookup value (D2) with each value in the lookup range (A3:A13), and if the match if found, returns the relative position of the row; an empty string ("") otherwise.
The relative positions of the rows are calculated by subtracting 2 from ROW($B$3:$B$13) so that the first row has position 1. If your return range begins in row 2, then subtract 1, and so on. The result of this operation is the array {1;2;3;4;5;6;7;8;9;10;11}, which goes to the value_if_true argument of the IF function.
Instead of the above calculation, you can use this expression: ROW(lookup_column)- MIN(ROW(lookup_column))+1, which returns the same result but does not require any changes regardless of the return column location. In this example, it'd be ROW($A$3:$A$13)- MIN(ROW($A$3:$A$13))+1.
So, at this point you have an array consisting of numbers (positions of matches) and empty strings (non-matches). For cell D3 in this example, we have the following array:
If you check with the source data, you will see that "Adam" (lookup value in D2) appears on the 3rd, 8th and 10th positions in the lookup range (A3:A13).
- SMALL function
Next, the SMALL(array, k) function steps in to determine which of the matches should be returned in a specific cell.With array already established, let's work out the k argument, i.e. the k-th smallest value to be returned. For this, you make a sort of an "incremental counter" ROW()-n, where "n" is the row number of the first formula cell minus 1. In this example, we entered the formula in cells D3:D7, so ROW()-2 returns "1" for cell D3 (row 3 minus 2), "2" for cell D4 (row 4 minus 2), etc.
As the result, the SMALL function pulls the 1st smallest element of the array in cell D3, the 2nd smallest element in cell D4, and so on. And this transforms the initial long and complex formula into a very simple one, like this:
Tip. To see the calculated value behind a certain part of the formula, select that part in the formula bar and press F9.
- INDEX function
This part is easy. You use the INDEX function to return the value of an array element based on its row number.
- IFERROR function
And finally, you wrap the formula in the IFERROR function to handle possible errors, which are inevitable because you cannot know how many matches will be returned for this or that lookup value, and therefore you copy the formula to a number of cells equal to or greater than the number of possible matches. Not to scare your users with a bundle of errors, simply replace them with an empty string (blank cell).
Note. Please notice the proper use of absolute and relative cell references in the formula. All references are fixed except for the relative column reference in the lookup value (D$2), which should change based on a relative position of a column(s) where the formula is copied to return matches for other lookup values.
Putting all this together, we get the following generic formulas to Vlookup multiple values in Excel:
Formula 1:
Formula 2:
Where:
- m is the row number of the first cell in the return range minus 1.
- n is the row number of the first formula cell minus 1.
Note. In the above example, both n and m are equal to "2" because our return range and formula range both begin in row 3. In your worksheets, these may be different numbers.
Formula 2. Vlookup multiple matches and return results in a row
In case you want to return multiple values in rows rather than columns, change the above formulas this way:
=IFERROR(INDEX($B$3:$B$13, SMALL(IF($D3=$A$3:$A$13, ROW($B$3:$B$13)-2,""), COLUMN()-4)),"")
Or
=IFERROR(INDEX($B$3:$B$13,SMALL(IF($D3=$A$3:$A$13,ROW($A$3:$A$13)- MIN(ROW($A$3:$A$13))+1,""),COLUMN()-4)), "")
Like in the previous example, both are array formulas, so remember to press the Ctrl + Shift + Enter shortcut to complete them correctly.
The formulas work with the same logic as in the previous example, except that you use the COLUM function instead of ROW to determine which matching value should be returned in a specific cell: COLUMN()-n. Where n is the column number of the first cell where the formula is entered minus 1. In this example, the formula is input in cells E2:H2. With E being the 5th column, n is equal to "4" (5-1=4).
Note. For the formula to get copied correctly to other rows, mind the lookup value references, absolute column and relative row, like $D3.
Wrapping up, here are the generic formulas for Vlookup with multiple results returned in rows:
Formula 1:
Formula 2:
Where:
- m is the row number of the first cell in the return range minus 1.
- n is the column number of the first formula cell minus 1.
Formula 3. Vlookup multiple matches based on multiple conditions
You already know how to Vlookup for multiple values in Excel based on one condition. But what if you want to return multiple matches based on two or more criteria? Taking the previous examples further, what if you have an additional Month column, and you are looking to get a list of all products sold by a given seller in a specific month?
If you are familiar with arrays formulas, you may remember that they allow using asterisk (*) as the AND operator. So, you can just take the formulas discussed in the two previous examples, and have them check multiple conditions as demonstrated below.
Return multiple matches in a column
Where:
- m is the row number of the first cell in the return range minus 1.
- n is the row number of the first formula cell minus 1.
Assuming the Seller list (lookup_range1) is in A3:A30, the Month list (lookup_range2) is in B3:B30, the seller of interest (lookup_value1) is in cell E3, and the month of interest (lookup_value2) is in cell F3, the formula takes the following shape:
=IFERROR(INDEX($C$3:$C$30, SMALL(IF(1=((--($E$3=$A$3:$A$30)) * (--($F$3=$B$3:$B$30))), ROW($C$3:$C$30)-2,""), ROW()-2)),"")
This layout may be useful for creating a dashboard, e.g. your users can enter a name in E3, month in F3 and get a list of products in column G:
Return multiple results in a row
If you want to pull multiple values based on multiple criteria sets, you may prefer the horizontal layout where results are returned in rows. In this case, use this following generic formula:
Where:
- m is the row number of the first cell in the return range minus 1.
- n is the column number of the first formula cell minus 1.
For our sample dataset, the formula goes as follows:
=IFERROR(INDEX($C$3:$C$30, SMALL(IF(1=((--($E3=$A$3:$A$30)) * (--($F3=$B$3:$B$30))), ROW($C$3:$C$30)-2,""), COLUMN()-6)),"")
And the result can resemble this:
In a similar manner, you can do multiple Vlookup with three, four or more conditions.
How these formulas work
Basically, the formulas to Vlookup multiple values with multiple conditions work with the already familiar logic, explained in the very first example. The only difference is that the IF function now tests multiple conditions:
The result of each lookup_value=lookup_range comparison is an array of logical values TRUE (condition is met) and FALSE (condition is not met). The double unary operator (--) coerces the logical values into 1's and 0's. And because multiplying by zero always gives zero, in the resulting array, you have 1 only for those elements that meet all of the specified conditions. Now, you simply compare the final array with number 1 so that the ROW function returns the numbers of rows that meet all the conditions, an empty string otherwise.
A word of caution. All of the multiple Vlookup formulas discussed in this tutorial are array formulas. As such, each formula iterates through all elements of the arrays every time the source data is changed or the worksheet is recalculated. On large worksheets containing hundreds or thousands of rows, this may significantly slow down your Excel.
If you need to get matches from several sheets, use this guide: How to VLOOKUP across multiple sheets.
How to Vlookup to return multiple values in one cell
I will be upfront - I don't know an easy way to lookup and return multiple matches in a single sell with formulas. However, I do know a formula-free (read "stress-free" :) way to do this by using two add-ins included with our Ultimate Suite for Excel. The detailed steps follow below.
Source data and expected result
As shown in the screenshot, we continue working with the dataset we've used in the previous example. But this time we want to achieve something different - instead of extracting multiple matches in separate cells, we want them to appear in a single sell, separated with a comma, space, or some other delimiter of your choosing.
Pull rows with multiple matches to the main table
In your main table, enter a list of unique names in the first column, months in the second column, and arrange them like shown in the screenshot below. After that, carry out the following steps:
- Select your main table or click any cell within it, and then click the Merge Two Tables button on the ribbon:
- The add-in is smart enough to identify and pick the entire table, so you just click Next:
Tip. When using the tool for the first time, it stands to reason to select the Create a backup copy of the worksheet box in case something goes wrong.
- Select the lookup table, and click Next.
- Choose one or more matching pairs of columns that should be compared in the main table and lookup table (in this example, it's the Seller and Month columns), and then click Next.
- Select the column(s) from which you want to pull matching values (Product in this example), and click Next.
- Tell the add-in how exactly you want multiple matches to be arranged in the main table. For this example, we need the following option: Insert rows with duplicate matching values after the row with the same value. Make sure that no other option is selected and click Finish.
At this point, you will have the following result - all matching rows are pulled to the main table and grouped by the values in the lookup columns - first by Seller, and then by Month:
The resulting table already looks nice, but it's not exactly what we wanted, right? As you remember, we are looking to Vlookup multiple matches and have them returned in a single sell, comma or otherwise separated.
Combine duplicates rows into one row
To merge "duplicate rows" in a single row, we are going to use another tool - Combine Rows Wizard.
- Select the table produced by the Merge Tables tool (please see the screenshot above) or any cell within the table, and click the Combine Rows button on the ribbon:
- Check if the add-in's got the table right, and click Next:
- Select the key column or columns (Seller and Month in this example), and click Next:
- Select the column(s) that contains multiple matches (Product in this example), choose the desired delimiter (semicolon, comma, space or line break), and click Finish.
Optionally, you can enable one of the additional features, or both:
- Delete duplicate values - if the column to be merged contains a few identical values, the first occurrence will be kept, duplicate matches will be deleted.
In this example, we do not check this option, and the add-in returns all found matches. For example, in cell C2, we have this string: Lemons, Bananas, Apples, Lemons, Bananas (please see the result on step 5 below). If you choose to delete duplicates, the result would be: Lemons, Bananas, Apples.
- Skip empty cells - self-explanatory :)
- Delete duplicate values - if the column to be merged contains a few identical values, the first occurrence will be kept, duplicate matches will be deleted.
- Allow the add-in a few seconds for processing, and you are all set!
This is how you can look up and return multiple values in Excel using our tools. If you are curious to give them a try, a fully-functional evaluation version of the Ultimate Suite is available for download below.
Available downloads
Vlookup Multiple Values - examples (.xlsx file)
Ultimate Suite - trial version (.exe file)
342 comments
Светлана, спасибо вам огромное за ваш форум. Начал составку очень трудного Excel spreadsheet сегодня, по знанию начиная почти с нуля по формулам. Последняя черта документа оставалась включить одну из этих формул упомянутых здесь. Туго было понимать но в конце концов понял где ошибка была, поправил и всё заработало! Как приятно что есть такие умные люди которые напишут как что делать ^^
Спасибо на добром слове, Егор! Приятно знать, что соотечественники нас тоже читают :)
I have a working formula to return multiple values from one Worksheet: "15".
Formula =IFERROR(INDEX('15'!$A$7:$A$41,SMALL(IF($I$1='15'!$G$7:$G$41,ROW('15'!$G$7:$G$41)-MIN(ROW('15'!G$7:$G$41))+1,""),ROW()-2)),"")
I would like the formula above to also go through each Worksheet and return multiple values.
I have created a working table name "Sheet_Name" that will dynamically list Worksheets 1 through 100 starting with Sheet 6, currently I have Worksheets: A, B, C, D, E, and 1 - 15 (data to return).
Sheet_Names Formula =OFFSET(SheetNames!$C$7,,,COUNT(SheetNames!$C7:$C106),1)
Well i have problem in using vlookup in pm mfsw worksheet
Hi,
I'm just wondering if Formula 3. Vlookup multiple matches based on multiple conditions can be used to retrieve data from other workbooks?
I've tried however have not been successful.
Many thanks
hello
Svetlana Cheusheva
Sorry to say but your formula does't work. they have some problem while applying in practical.
so can you help me ?
Hello!
Please feel free to download our sample workbook with all the formulas described in this tutorial, and try them on your data.
How do I get the formula to search for match part of the string like APP instead of the full word APPLE?
am doing food gram as per menu for one person, when it is 100 person the gram reduce same items =IFERROR(VLOOKUP($B$6:$B$32,GRAM!$A$1:$B$300,2,FALSE)," 0 " )
this formula will look out value in gram A1:A300 FOR SAY CHICKEN for one person , I NEED IT LOOK FOR MULTIPLE1 cells where i stored for 1 pax, 100 pax 200pax etc. it has diferent grams. kindly advise.
I have applied the array formula and it worked perfectly. I would now like to apply another formula to my listed results (in one column) in order to extract my distinct texts to the column next to it. My data from this formula has multiple texts vertically and I would like each unique data only repeated once (next to the first) in the next column and blanks following until the next unique text.
Or just extracting the distinct values off of this formula.
Is this possible?
I look forward to your response. Thank you.
i want to apply the formula on a sheet.
like i have criteria range and infront of value if my first criteria value is 0 than for same criteria v lookup should take the value for next criteria.
Regards
Yogendra
i want to extract two unique different column of data in to one cell from another sheet after searching through an array
a b c(ans)
1 4 2
2 3 1
3 4 2
4 2 4
Awesome tutorial, thanks a lot!
Hello Svetlana,
The issue I experienced not pulling the data was related to #N/A (error) in couple of cells. Once I replaced these values all worked fine.
Sorry for the formatting above, but it only became so after I posted the message. There are currently 7 columns, one with the A/A numbers and another 6 with data. A,B,C,D,E and F are the head titles of the 6 columns with the data.
Hello Svetlana.
I have the following table. Please have a look at my question following the table.
A B C D E F
1 EXCB11 EXCB10 0.202 0.79 0.159 0.159
2 EXCB10 EXCB09 0.117 0.72 0.084 0.244
3 EXCB09 EXCB08 0.042 0.61 0.026 0.269
4 EXCB08 EXSTMH05 0.016 0.2 0.273
5 EXSTMH07 EXSTMH09 0.016 0.5
6 EXSTMH08 EXSTMH07 ? ?
7 NEWCB12 NEWSTMH04 0.152 0.76 0.115
8 NEWSTM EXSTMH05 0.178 0.76 0.250
9 NEWCB14 NEWSTMH15 0.093 0.83 0.078
10 NEWSTMH15 NEWSTMH13 0.000 0.92
11 NEWSTMH13 EXSTMH08 0.000 0.76
12 EXSTMH0 EXSTMH05 0.019 0.59 0.089
13 EXSTMH05 TMNT DEVICE 0.000 0.59
14 TMNT DEVICE EXMH01 0.000 0.87 0.000
- For every cell of column A, I am trying to find the cells in Column B that have the same value with it. For example in the given table for Cell A13 that has the value EXSTMH05, I would like to find cells B4, B8 and B12 that also have the value EXSTMH05.
- Then, for each one of the cells that I found I want to get the values from the respective cell of Column F and sum them up. So, in the given example I would like to get the values from F4, F8 and F12 and find their sum. The result I am seeking in this example 0.273+0.250+0.089.
Can you help me? I have tried using various formulas but to no result.
Hi Svetlana,
I wanted to ask you for your help with my table:
https://we.tl/mMztWNG1lY
What I would like to display in Sheet 2, is the quantity of those topics, which meet the chosen criteria and also display all corresponding texts, links and clicks, one below the other, taking in account the two criteria chosen at the top: "Category" and "Language".
What we also have to take in account is that the categories, texts, links and clicks can be found in several columns and not just in one.
I really hope that you can help me with this issue. :)
Best regards,
Sanjin
Svetlana,
Spasiba, for your quick response. Everything is working well even on large volume of data. When the data is aligned well n-1 type of configuration it works well.
As for the "relative reference" I meant relative position. I tried multiple examples, the all worked if properly setup.
Cheers,
Sam
Hello,
I'm hitting a unique error with this formula. I have the formula on Sheet2, and am trying to pull the information from Sheet1, A4, titled "Expirations". In the "IF" statement, if I put the reference item to match the item in the first row of the table on sheet 1 (89), it pulls the information from A4 over after I hit Enter. If I change it match the item in row 2 (229), it doesn't pull the associated info from A5. Also, if I hit ctrl+shft+enter to use this as an array formula, it doesn't pull any results.
My ultimate goal is to pull over all of the rows that have a negative number in Column E, so if you can offer any guidance towards that, that would be awesome. :) But in the meantime, helping me understand why the array formula isn't working between worksheets, and why it only pulls over the first item when used as a standard formula, would be awesome. The formula I'm using is:
=IFERROR(INDEX(Expirations!A$4:A$2864, SMALL(IF(89=Expirations!$E$4:$E$2864,ROW(Expirations!A$4:A$2864)-3,""), ROW()-3)),"")
Thank you!
Kevin
Svetlana.
Great work. The formula works well even in Two workbooks format one for data and one for matching. Also worked when replacing relative values with Named Ranges. I extended the example to about 6000 rows, still works. Note the slight change with named ranges "D$2=Sellers, Row(Seller)" Using Row(Fruits) does not return results.
=IFERROR(INDEX($B$3:$B$13, SMALL(IF(D$2=$A$3:$A$13, ROW($B$3:$B$13)-2,""), ROW()-2)),"")
=IFERROR(INDEX(Fruits, SMALL(IF(D$2=Sellers, ROW(Sellers)-2,""), ROW()-2)),"")
My trouble is, I have a very large data set (about 20K+ rows) and I get only the first value repeating for the entire array in my real work. I can't figure out where am I going wrong.
Hi Sam,
Sorry, I do not quite understand the part about relative references. In the original formula, all ranges are fixed (absolute references), and in named ranges the references are also absolute by default. I've done the same replacement in the sample workbook, and it works just fine. Please see N3:Q5 in sheet "Return matches in columns". The updated file can be downloaded here.
Hi Svetlana Cheusheva, in your first formula with index and Row-2 example above. I do scores for softball league and I need to look up the teams identifier (e.g. 10a) and return the date of the game. However, the column range I need to look in houses the matchups for that day's games. e.g. 10a v 10b in a cell. Can I use wildcards in the array formula (e.g. *10a*) as my look up value vs just 10a. I tried doing "*10a*", but got a Num error (took out the iferror to see why blank). Do I have to input "*"&D3(being 10a)&"*"=C2:c27, etc.??? Any guidance here is much appreciated!
Wow! very well written and expressed. Exactly what I wanted the first formula itself. Thank you!