Advanced VLOOKUP in Excel: multiple, double, nested

These examples will teach you how to Vlookup multiple criteria, return a specific instance or all matches, do dynamic Vlookup in multiple sheets, and more.

It is the second part of the series that will help you harness the power of Excel VLOOKUP. The examples imply that you know how this function works. If not, it stands to reason to start with the basic uses of VLOOKUP in Excel.

Before moving further, let me briefly remind you the syntax:

VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])

Now that everyone is on the same page, let's take a closer look at the advanced VLOOKUP formula examples:

How to Vlookup multiple criteria

The Excel VLOOKUP function is really helpful when it comes to searching across a database for a certain value. However, it lacks an important feature - its syntax allows for just one lookup value. But what if you want to look up with several conditions? There are a few different solutions for you to choose from.

Formula 1. VLOOKUP with two criteria

Suppose you have a list of orders and want to find the quantity based on 2 criteria, Customer name and Product. A complicating factor is that each customer ordered multiple products, as shown in the table below:
VLOOKUP based on two values – source data

A usual VLOOKUP formula won't work in this situation because it returns the first found match based on a single lookup value that you specify.

To overcome this, you can add a helper column and concatenate the values from two lookup columns (Customer and Product) there. It is important that the helper column should be the leftmost column in the table array because it's where Excel VLOOKUP always searches for the lookup value.

So, add a column to the left of your table and copy the below formula across that column. This will populate the helper column with the values from columns B and C (the space character is concatenated in between for better readability):

=B2&" "&C2

And then, use a standard VLOOKUP formula and place both criteria in the lookup_value argument, separated with a space:

=VLOOKUP("Jeremy Sweets", A2:D11, 4, FALSE)

Or, input the criteria in separate cells (G1 and G2 in our case) and concatenate those cells:

=VLOOKUP(G1&" "&G2, A2:D11, 4, FALSE)

As we want to return a value from column D, which is fourth in the table array, we use 4 for col_index_num. The range_lookup argument is set to FALSE to Vlookup an exact match. The screenshot below shows the result:
VLOOKUP with two criteria

In case your lookup table is in another sheet, include the sheet's name in your VLOOKUP formula. For example:

=VLOOKUP(G1&" "&G2, Orders!A2:D11, 4, FALSE)

Alternatively, create a named range for the lookup table (say, Orders) to make the formula easier-to-read:

=VLOOKUP(G1&" "&G2, Orders, 4, FALSE)

For more information, please see How to Vlookup from another sheet in Excel.

Note. For the formula to work correctly, the values in the helper column should be concatenated exactly the same way as in the lookup_value argument. For example, we used a space character to separate the criteria in both the helper column (B2&" "&C2) and VLOOKUP formula (G1&" "&G2).

Formula 2. Excel VLOOKUP with multiple conditions

In theory, you can use the above approach to Vlookup more than two criteria. However, there are a couple of caveats. Firstly, a lookup value is limited to 255 characters, and secondly, the worksheet's design may not allow adding a helper column.

Luckily, Microsoft Excel often provides more than one way to do the same thing. To Vlookup multiple criteria, you can use either an INDEX MATCH combination or the XLOOKUP function recently introduced in Office 365.

For example, to look up based on 3 different values (Date, Customer name and Product), use one of the following formulas:

=INDEX(D2:D11, MATCH(1, (G1=A2:A11) * (G2=B2:B11) * (G3=C2:C11), 0))

=XLOOKUP(1, (G1=A2:A11) * (G2=B2:B11) * (G3=C2:C11), D2:D11)

Where:

  • G1 is criteria 1 (date)
  • G2 is criteria 2 (customer name)
  • G3 is criteria 3 (product)
  • A2:A11 is lookup range 1 (dates)
  • B2:B11 is lookup range 2 (customer names)
  • C2:C11 is lookup range 3 (products)
  • D2:D11 is the return range (quantity)

VLOOKUP multiple criteria

Note. In all versions except Excel 365, INDEX MATCH should be entered as an CSE array formula by pressing Ctrl + Shift + Enter. In Excel 365 that supports dynamic arrays it also works as a regular formula.

For the detailed explanation of the formulas, please see:

How to use VLOOKUP to get 2nd, 3rd or nth match

As you already know, Excel VLOOKUP can fetch only one matching value, more precisely, it returns the first found match. But what if there are several matches in your lookup array and you want to get the 2nd or 3rd instance? The task sounds quite intricate, but the solution does exist!

Formula 1. Vlookup Nth instance

Suppose you have customer names in one column, the products they purchased in another, and you are looking to find the 2nd or 3rd product bought by a given customer.

The simplest way is to add a helper column to the left of the table like we did in the first example. But this time, we will populate it with customer names and occurrence numbers like "John Doe1", "John Doe2", etc.

To get the occurrence, use the COUNTIF function with a mixed range reference (the first reference is absolute and the second is relative like $B$2:B2). Since the relative reference changes based on a position of the cell where the formula is copied, in row 3 it will become $B$2:B3, in row 4 - $B$2:B4, and so on.

Concatenated with the customer name (B2), the formula takes this form:

=B2&COUNTIF($B$2:B2, B2)

The above formula goes to A2, and then you copy it down to as many cells as needed.

After that, input the target name and occurrence number in separate cells (F1 and F2), and use the below formula to Vlookup a specific occurrence:

=VLOOKUP(F1&F2, A2:C11, 3, FALSE)
Vlookup Nth instance

Formula 2. Vlookup 2nd occurrence

If you are looking for the 2nd instance of the lookup value, then you can do without the helper column. Instead, create the table array dynamically by using the INDIRECT function together with MATCH:

=VLOOKUP(E1, INDIRECT("A"&(MATCH(E1, A2:A11, 0)+2)&":B11"), 2, FALSE)

Where:

  • E1 is the lookup value
  • A2:A11 is the lookup range
  • B11 is the last (bottom-right) cell of the lookup table
    Vlookup 2nd occurrence

Please note that the above formula is written for a specific case where data cells in the lookup table begin in row 2. If your table is somewhere in the middle of the sheet, use this universal formula, where A1 is the top-left cell of the lookup table containing a column header:

=VLOOKUP(E1, INDIRECT("A"&(MATCH(E1, A2:A11, 0)+1+ROW(A1))&":B11"), 2, FALSE)

How this formula works

Here is the key part of the formula that creates a dynamic vlookup range:

INDIRECT("A"&(MATCH(E1, A2:A11, 0)+2)&":B11")

The MATCH function configured for exact match (0 in the last argument) compares the target name (E1) against the list of names (A2:A11) and returns the position of the first found match, which is 3 in our case. This number is going to be used as the starting row coordinate for the vlookup range, so we add 2 to it (+1 to exclude the first instance and +1 to exclude row 1 with the column headers). Alternatively, you can use 1+ROW(A1) to calculate the necessary adjustment automatically based on the position of the header row (A1 in our case).

As the result, we get the following text string, which INDIRECT converts to a range reference:

INDIRECT("A"&5&":B11") -> A5:B11

This range goes to the table_array argument of VLOOKUP forcing it to start searching in row 5, leaving out the first instance of the lookup value:

VLOOKUP(E1, A5:B11, 2, FALSE)

How to Vlookup and return multiple values in Excel

The Excel VLOOKUP function is designed to return just one match. Is there a way to Vlookup multiple instances? Yes, there is, though not an easy one. This requires a combined use of several functions such as INDEX, SMALL and ROW is an array formula.

For example, the below can find all occurrences of the lookup value F2 in the lookup range B2:B16 and return multiple matches from column C:

{=IFERROR(INDEX($C$2:$C$11, SMALL(IF($F$1=$B$2:$B$11, ROW($C$2:$C$11)-1,""), ROW()-1)),"")}

There are 2 ways to enter the formula in your worksheet:

  1. Type the formula in the first cell, press Ctrl + Shift + Enter, and then drag it down to a few more cells.
  2. Select several adjacent cells in a single column (F1:F11 in the screenshot below), type the formula and press Ctrl + Shift + Enter to complete it.

Either way, the number of cells in which you enter the formula should be equal to or larger than the maximum number of possible matches.
Vlookup multiple values

For the detailed explanation of the formula logic and more examples, please see How to VLOOKUP multiple values in Excel.

How to Vlookup in rows and columns (two-way lookup)

Two-way lookup (aka matrix lookup or 2-dimentional lookup) is a fancy word for looking up a value at the intersection of a certain row and column. There are a few different ways to do two-dimensional lookup in Excel, but since the focus of this tutorial is on the VLOOKUP function, we will naturally use it.

For this example, we'll take the below table with monthly sales and work out a VLOOKUP formula to retrieve the sales figure for a specific item in a given month.

With item names in A2:A9, month names in B1:F1, the target item in I1 and the target month in I2, the formula goes as follows:

=VLOOKUP(I1, A2:F9, MATCH(I2, A1:F1, 0), FALSE)
Vlookup in rows and columns

How this formula works

The core of the formula is the standard VLOOKUP function that searches for an exact match to the lookup value in I1. But since we do not know in which exactly column the sales for a specific month are, we cannot supply the column number directly to the col_index_num argument. To find that column, we use the following MATCH function:

MATCH(I2, A1:F1, 0)

Translated into English, the formula says: look up the I2 value in A1:F1 and return its relative position in the array. By supplying 0 to the 3rd argument, you instruct MATCH to find the value exactly equal to the lookup value (it's like using FALSE for the range_lookup argument of VLOOKUP).

Since Mar is in the 4th column in the lookup array, the MATCH function returns 4, which goes directly to the col_index_num argument of VLOOKUP:

VLOOKUP(I1, A2:F9, 4, FALSE)

Please pay attention that although the month names start in column B, we use A1:I1 for the lookup array. This is done in order for the number returned by MATCH to correspond to the column's position in table_array of VLOOKUP.

To learn more ways to perform matrix lookup in Excel, please see INDEX MATCH MATCH and other formulas for 2-dimensional lookup.

How to do multiple Vlookup in Excel (nested Vlookup)

Sometimes it may happen that your main table and lookup table do not have a single column in common, which prevents you from doing a Vlookup between two tables. However, there exists another table, which does not contain the information you are looking for but has one common column with the main table and another common column with the lookup table.

In below image illustrates the situation:
Nested Vlookup in Excel

The goal is to copy prices to the main table based on Item IDs. The problem is that the table containing prices does not have the Item IDs, meaning we will have to do two Vlookups in one formula.

For the sake of convenience, let's create a couple of named ranges first:

  • Lookup table 1 is named Products (D3:E10)
  • Lookup table 2 is named Prices (G3:H10)

The tables can be in the same or different worksheets.

And now, we will perform the so-called double Vlookup, aka nested Vlookup.

First, make a VLOOKUP formula to find the product name in the Lookup table 1 (named Products) based on the item id (A3):

=VLOOKUP(A3, Products, 2, FALSE)

Next, put the above formula in the lookup_value argument of another VLOOKUP function to pull prices from Lookup table 2 (named Prices) based on the product name returned by the nested VLOOKUP:

=VLOOKUP(VLOOKUP(A3, Products, 2, FALSE), Prices, 2, FALSE)

The screenshot below shows our nested Vlookup formula in action:
Multiple (nested) Vlookup in Excel

How to Vlookup multiple sheets dynamically

Sometimes, you may have data in the same format split over several worksheets. And your aim is to pull data from a specific sheet depending on the key value in a given cell.

This may be easier to understand from an example. Let's say, you have a few regional sales reports in the same format, and you are looking to get the sales figures for a specific product in certain regions:
VLOOKUP multiple sheets dynamically

Like in the previous example, we start with defining a few names:

  • Range A2:B5 in CA sheet is named CA_Sales.
  • Range A2:B5 in FL sheet is named FL_Sales.
  • Range A2:B5 in KS sheet is named KS_Sales.

As you can see, all the named ranges have a common part (Sales) and unique parts (CA, FL, KS). Please be sure to name your ranges in a similar manner as it's essential for the formula we are going to build.

Formula 1. INDIRECT VLOOKUP to dynamically pull data from different sheets

If your task is to retrieve data from multiple sheets, a VLOOKUP INDIRECT formula is the best solution – compact and easy-to-understand.

For this example, we organize the summary table in this way:

  • Input the products of interest in A2 and A3. Those are our lookup values.
  • Enter the unique parts of the named ranges in B1, C1 and D1.

And now, we concatenate the cell containing the unique part (B1) with the common part ("_Sales"), and feed the resulting string to INDIRECT:

INDIRECT(B$1&"_Sales")

The INDIRECT function transforms the string into a name that Excel can understand, and you put it in the table_array argument of VLOOKUP:

=VLOOKUP($A2, INDIRECT(B$1&"_Sales"), 2, FALSE)

The above formula goes to B2, and then you copy it down and to the right.

Please pay attention that, in the lookup value ($A2), we've locked the column coordinate with absolute cell reference so that the column remains fixed when the formula is copied to the right. In the B$1 reference, we locked the row because we want the column coordinate to change and supply an appropriate name part to INDIRECT depending on the column into which the formula is copied:
VLOOKUP and INDIRECT to dynamically pull data from multiple sheets

If your main table is organized differently, the lookup values in a row and unique parts of the range names in a column, then you should lock the row coordinate in the lookup value (B$1) and the column coordinate in the name parts ($A2):

=VLOOKUP(B$1, INDIRECT($A2&"_Sales"), 2, FALSE)
INDIRECT VLOOKUP in Excel

Formula 2. VLOOKUP and nested IFs to look up multiple sheets

In situation when you have just two or three lookup sheets, you can use a fairly simple VLOOKUP formula with nested IF functions to select the correct sheet based on the key value in a particular cell:

=VLOOKUP($A2, IF(B$1="CA", CA_Sales, IF(B$1="FL", FL_Sales, IF(B$1="KS", KS_Sales,""))), 2, FALSE)

Where $A2 is the lookup value (item name) and B$1 is the key value (state):
VLOOKUP and nested IFs to return data from multiple sheets

In this case, you do not necessarily need to define names and can use external references to refer to another sheet or workbook.

For more formula examples, please see How to VLOOKUP across multiple sheets in Excel.

That's how to use VLOOKUP in Excel. I thank you for reading and hope to see you on our blog next week!

Practice workbook for download

Advanced VLOOKUP formula examples (.xlsx file)

540 comments

  1. Instead of images, if you can use actual tables for your examples, we can copy and experiment in our Excel environment. Thank you!

  2. I've been working on a 2 criteria VLookup and have it working, but I need to know if there's a way to display the found data in the same format as it exists in the source table.
    The columns I'm pulling data from may contain "$ values", or "% values".
    (Ex: Where 'Name=Neal' and 'Month=Mar')

    Name Jan Feb Mar Apr May Jun
    Pete $26 $34 $33 $37 $41 $44
    Sally $41 $29 $0 $49 $24 $34
    Neal $42 $36 100% $38 $25 $37
    Diana $40 $18 0% $38 $35 $32

    I've tried using conditional formatting on the 'results' fields, to change the format based on value, but I can't figure out when "'$0' vs '0%'", 100% vs $100, etc.

    I thought I could expand my vlookup to include the Cell() function to return the formatting, but don't know if this is the nest way.
    Any thoughts?

  3. if i have data like

    code code no.
    1001 2001 1
    1002 3001 2
    1003 1001 3

    i want to lookup 1001 in different work book & no. infron of code

    kindly help which formula to use

  4. very useful info you have there. thank you very much. but i could not make the formula work. can you please help me? i use vlookup for a specific text(column A) and data next cell (column B, col_index_num)) but when the text is in more than one cell, i need the different datas concatenated with space. Can you please type the formula?

  5. Hi There
    I you can help. I am trying to get the below formula to work. It is bringing me back the Case values but N/A for anything else.
    Essentially I have a code in a cell and I want to know which column this code corresponds from three columns of codes on another sheet.
    This is the formula I have tried. I have tries nesting IF statements combined with vlookup statements. If at all possible I would like to have this all in one cell rather than spread out. Any help would be much appreciated.
    =IF(A2=VLOOKUP(A2,Compare!H:H,1,FALSE),"Case",IF(A2=VLOOKUP(Sheet1!A2,Compare!G:G,1,FALSE),"Shrink","Item"))

    I have also tried

    =IF(VLOOKUP(A2,Compare!H:H,1,FALSE)=A2,"Case",IF(VLOOKUP(Sheet1!A2,Compare!G:G,1,FALSE)=A2,"Shrink","Item"))

  6. Dear sir,
    If you please help me to solve the problem.

    I have
    (Sheet 1)
    A=1
    B=2
    C=2
    A=4
    B=5
    C=6
    I want(Sheet 2)
    Sum of A=?
    B=?
    C=?
    I Will be highly oblized to you.

    Regards
    Pappu Pattanayak

    • Hi Pappu,
      You can use below simple command
      Think its in one sheet and result is also published in one sheet
      =SUMIFS($B$:$B$,$A$:$A$,D1)

  7. Can anybody help me with this:
    example:
    Col.A Column B
    States Sales Rep Name
    AZ, CA Blank
    WA,ID,OR Blank
    TX, OK, Blank

    in column A, there's abbreviation of states, like CA, NV, AZ etc...
    I need to conduct a Vlookup that searches the range of these states in (A) and cross references the master Table (on another sheet) to populate Column B. My challenge is that i can't find a Vlookup to search the range of 50 states. Any suggestions?
    thank you

  8. Hello,

    I have sales for about 1000 customers split by various services all grouped into one invoice by split by line item. I need to pull this information and insert the values of each service by customer in a table.
    Source:
    Client 1 Plumbing done on 11th $500
    Client 1 Plumbing done on 24th $500
    Client 1 Work done for Carpentry $1000
    Client 2 Plumbing was done on 25th $1000
    Client 2 Installation done on 10th $250
    Client 2 Carpentry done on 10th $700
    Client 2 Carpentry done on 10th $1700

    I need this info in the below table format (Note, I need sum of each service for each client)

    Clients, Plumbing, Carpentry,Installation
    Client 1 $1000 $1000 0
    Client 2 $1000 $2400 $250

    The above information looks simple, but the description of each item is a sentence out of which I need to pick a "code word" to identify the service. Thank you so much for your help!

  9. =VLOOKUP("Lemons",$A$2:$I$9,MATCH("Mar",$A$1:$I$1,0),FALSE)

    Working with this formula, but getting the #N/A error.

    Material Material Description 8/1 7/25 7/18
    105939 EBF Org Wild Arugula 2x2lb PL 574 1,350 21,321
    105940 EBF Org Baby Spin - 2x2lb PL 1,741 1,345 1,564
    2,315 2,695 22,885

    • Need to lookup a material (105940) and bring the qty. on a specific date (7/18). Does this not work because it's trying to reference dates?

  10. I have a excel file where I daily populate cash transactions for several bank accounts. I need to a daily rollfoward with beginning to eOD balances. I prepared a tab for each account and the date in column A and columns B thru J have the cash category. I performed a pivot table that has Account,date,category and total. I need to find a way to drop the data from each bank account into each tab I made so the rollforward can be updated by a simple refresh. I think this can be done using complex if then and combine Hlookup tables but I am not able to drop each dollar amount in its corresponding category by date

  11. Dear Sir,
    I am using Microsoft excel 2007 I want to use vlookup formulla with 3 lacs column but it could not work, it shows error message "invalid reference and this file verson can not contain formulla that reference cell beyond a worksheet size of 236 column (column IW of higher) or 65536 rows".
    I don't understand please help me what I do??????????

  12. Hi, can you help me with this.
    *ship mode minus "H" the order priority "D"
    These are the columns and the data are in words.
    Info tab has all the numbers that corresponds to the H and D columns:

    Order Priority
    1 Low 3
    2 High 5
    3 Not Specified 0
    4 Critical 7

    Ship Mode
    1 Regular Air 10
    2 Delivery Truck 15
    3 Express Air 7

    What formula should I use and can you help me with this one?

  13. Hi All

    Need your help regarding Vlookup, my date contains

    Date
    Product Name
    Opening Stock
    Issued Qty.
    Bal. Qty.

    I need to lookup for two criteria, e.g. data of specific date and product

  14. Example:-

    Sheet one:-
    Serial_numbers
    Abc
    DEF
    GHI
    JKL

    Sheet two:-
    Serial_numbers supplier
    ABC,DEF,GHI Amazon
    ABC,GHI Ebay
    JKL,ABC Flipkart

    I want the details like below

    Serial_numbers supplier
    Abc Amazon
    DEF Amazon
    GHI EBAY
    JKL Flipkart.

    Like this i have around 50k line items.

  15. Hi All,

    I have one question please some one help me to fix it.

    I have two tables one table is having only Serial numbers with removing duplicate
    Another table serial numbers like 10 serial numbers in one column with other details like products suppliers resellers etc.

    Here i want to perform vlookup for unique serial number table and get the supplier details to it.

    please help me some one. thanks

    • Like this 10 serial numbers i have in some 250 and more than 250 characters length serial numbers column, i want supplier information from this sheet to the original sheet.

  16. Hi Svet,

    It's my first time to visit your site and it very helpful. I need your advise on how to make my project more efficient in a way. I'm creating a monthly scorecard that goals may vary from time to time and has multiple ranges to use. Sample data below:

    Inbound
    0% 15% 30% 45% 50% 65% 75% 85% 90% 95% 98% 100% Weight

    Attendance 80% 82% 86% 89% 90% 92% 93% 94% 95% 96% 98% 100% 15.0%

    SO there's the month, range of score to get (fixed to 0% 15% 30% 45% 50% 65% 75% 85% 90% 95% 98% 100%) and the weight as the last column (say, if agent gets 90% in attendance, he gets 50% * the weight applied of 15%. That weighted score should be summed up with all other KPI weighted score to get the 100% computation for that month. Im sending out the file to your email. :)

    Thanks in Advance!
    Paul

  17. hi i'm trying to use vlookup to pull data from multiple sheets. i'm ok with vlookup within a sheet but how do i read a sheet name from a cell then go to that sheet and use vlookup normally. basically i have sheet with a list of other sheets in it this list changes from an outside data source so i need to read the sheet name and return some data from this sheet.

  18. Oh sorry, I am using VBA...

  19. "How to get all duplicate values in the lookup range" -- your information here is great! I need to know how to do the above using VLookup. Index and Match do not seem to work. I am using Excel 2013. This is my issue:

    Column A has 1's and Null values; Column F has the Data that I need to copy.
    I need All of the Data in Column F as long as Column A is not null.
    Example
    Column A Column F
    cell1 = 1 "West"
    cell2 = Null "East"
    cell3 = 1 "West"
    cell4 = 1 "East"
    cell5 = 1 "South"
    cell6 = Null "South"

  20. I am trying to write a formula that if column B&C is empty it bring nothing. If C has something it must bring what is in column A and if B has something it must bring what is in column A.

    A B C
    L1125A110 L1132A117
    L1130A031
    L1130A066
    L1140A026
    L1145A019
    L1145A031
    L1145A043 LMD322641
    L1145A049
    L1145A051 LMD342154
    L1145A067 LMD193875
    L1145A070 LMD197622
    L1200A147
    L1200A312
    L1211A021
    L1211A039
    L1226A003
    L1230A040
    L1230A046 L1230A154
    L1250A010
    L1250A015 LMD354664

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)