Yes, you can put a VLOOKUP inside another VLOOKUP in Excel, and the most common reason to do it is to look up a value from a second table after first finding a matching key in a first table. For example, to find an employee’s department name, you might first VLOOKUP the employee’s department ID from one table, then feed that ID into a second VLOOKUP to get the department name from another table. This is called a nested VLOOKUP, and it works because the inner VLOOKUP returns a value that the outer VLOOKUP uses as its lookup value.
What Is a Nested VLOOKUP?
A nested VLOOKUP is simply a VLOOKUP formula written inside another VLOOKUP’s lookup_value argument. Instead of typing a fixed value like "A1" or "D3", you put a complete VLOOKUP formula there. Excel evaluates the inner formula first, gets a result, and then uses that result as the search key for the outer formula.
Here is the general structure:
=VLOOKUP( VLOOKUP(lookup_value, inner_table, col_index, FALSE), outer_table, col_index, FALSE)
The inner VLOOKUP must return a value that exists in the first column of the outer table. If it does not, the outer VLOOKUP returns #N/A.
When Would You Need a Nested VLOOKUP?
The most typical scenario is when your data is split across two tables and you need to connect them through an intermediate code or ID. For instance:
- Table 1 (Orders): Order ID, Product ID, Quantity
- Table 2 (Products): Product ID, Product Name, Category ID
- Table 3 (Categories): Category ID, Category Name
If you want to show the category name for each order, you need to go from Order to Product ID (Table 1), then to Category ID (Table 2), then to Category Name (Table 3). A nested VLOOKUP can do the last two steps in one formula: the inner VLOOKUP gets the Category ID from Table 2, and the outer VLOOKUP gets the Category Name from Table 3.
Nested VLOOKUP Example with Real Data
Let’s build a concrete example. Suppose you have the following data in a worksheet:
- A1:C5 – Employee table: Employee ID (col A), Employee Name (col B), Department ID (col C)
- E1:F4 – Department table: Department ID (col E), Department Name (col F)
Data:
A1: 101 B1: Alice C1: D01
A2: 102 B2: Bob C2: D02
A3: 103 C3: Carol C3: D01
A4: 104 B4: David C4: D03
A5: 105 B5: Eve C5: D02
E1: D01 F1: Sales
E2: D02 F2: Marketing
E3: D03 F3: HR
To get the department name for the employee in A2 (Bob), you would write:
=VLOOKUP(VLOOKUP(A2, A1:C5, 3, FALSE), E1:F4, 2, FALSE)
How it works:
- Inner VLOOKUP:
VLOOKUP(A2, A1:C5, 3, FALSE)looks for 102 in A1:A5, finds it in row 2, and returns the value from column 3 of that row, which isD02. - Outer VLOOKUP:
VLOOKUP("D02", E1:F4, 2, FALSE)looks for D02 in E1:E4, finds it in row 2, and returnsMarketing.
The formula returns Marketing. If you copy it down for other employee IDs, it will return each employee’s department name.
How to Choose the Right Lookup Order
Deciding which VLOOKUP goes inside and which goes outside is a matter of following the data flow. The inner VLOOKUP should return the value that the outer VLOOKUP needs as its search key. Ask yourself: “What do I know now, and what do I need to find?”
- If you know an ID and need a name, the ID is the lookup value, the table with the ID and name is the table, and the name is the result.
- If you need to go through two hops, the first hop (from known to intermediate) is the inner VLOOKUP, and the second hop (from intermediate to final) is the outer VLOOKUP.
Always use FALSE for exact match unless you truly need approximate matching (which is rare and usually for numeric ranges). With FALSE, the lookup value must exist exactly in the first column of the table.
Common Problems and How to Fix Them
Nested VLOOKUPs often fail for a few predictable reasons:
- #N/A error: The inner VLOOKUP returned a value that is not in the first column of the outer table. Check that the intermediate value exists and that there are no extra spaces or number-format differences.
- #VALUE! error: The inner VLOOKUP returned text where a number is expected, or vice versa. Make sure the data types match.
- Column index out of range: If the column index number is greater than the number of columns in the table, you get a #REF! error. Double-check your ranges.
- Table ranges not locked: When copying the formula down, if you don’t use absolute references (like
$A$1:$C$5), the ranges shift and cause errors. Press F4 (on Windows) or Cmd+T (on Mac) to lock ranges.
Also, nested VLOOKUPs are limited to a single lookup value. If you need to return multiple columns from the outer table, you could use INDEX/MATCH instead, which is often more flexible.
Alternatives to Nested VLOOKUP
Nested VLOOKUP works, but it can be hard to read and debug. Here are two common alternatives:
- Helper column: Add a column that calculates the intermediate value once, then use a regular VLOOKUP on that helper column. This makes the formulas simpler and easier to audit.
- INDEX and MATCH: You can nest a MATCH inside an INDEX to achieve the same two-step lookup. For example:
=INDEX(F1:F4, MATCH(VLOOKUP(A2, A1:C5, 3, FALSE), E1:E4, 0)). This is more flexible because you can return values from any column, not just the rightmost one.
For Excel 2021 or Microsoft 365, you could also use XLOOKUP, which can be nested in a similar way: =XLOOKUP(XLOOKUP(A2, A1:A5, C1:C5), E1:E4, F1:F4). XLOOKUP is generally easier to read.
Frequently Asked Questions
Can I nest more than two VLOOKUPs? Yes, you can nest three or more VLOOKUPs, but each level adds complexity and makes the formula harder to debug. Excel allows up to 64 levels of nesting, but practically, beyond two or three, you should consider a helper column or a different approach.
Does the inner VLOOKUP need to be in the same sheet? No, the inner and outer VLOOKUPs can refer to different sheets or even different workbooks, as long as the references are valid. For example, you could have the inner table on Sheet2 and the outer table on Sheet3.
What if the inner VLOOKUP returns multiple matches? VLOOKUP with FALSE returns only the first match. If your data has duplicate lookup values, the result may be unpredictable. Use a unique key or consider using INDEX/MATCH with additional criteria.
Why do I get #N/A even though the value looks correct? Often this is due to invisible characters like trailing spaces, or numbers stored as text. Use the TRIM function or convert text to numbers with VALUE. Also check that the lookup value and the first column have the same data type.
Is there a performance issue with nested VLOOKUPs? On large datasets (tens of thousands of rows), nested VLOOKUPs can slow down calculation because each VLOOKUP performs a search. For better performance, consider using a single INDEX/MATCH or XLOOKUP, or use Power Query to merge tables.
Can I use a nested VLOOKUP to return a value from a column to the left of the lookup column? No, VLOOKUP can only return values from columns to the right of the first column. If you need to return a value from a column to the left, use INDEX/MATCH or XLOOKUP.
Related
- Shortcut for Clipboard: Paste Faster in Windows
- Role of Data Entry: Tasks, Tools, and Career Path
- Google Sheets Percentage of a Cell: How To
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Countifs Count Blank Cells? Answer & WorkaroundsNo, the COUNTIFS function in Excel does not count truly blank cells when you use the criteria ""…
- Excel Concatenate Strings: The 4 Best WaysThe simplest way to concatenate (join) strings in Excel is to use the ampersand operator (&), like =A1&"…
- Excel COUNTIF Contains Partial Text: Formula GuideThe formula to count cells containing partial text in Excel is =COUNTIF(range,"*text*"). Replace range with your cell range…
- Structured Reference Excel Formula: Syntax and ExamplesA structured reference formula uses an Excel table’s name and column headings instead of ordinary cell addresses. For…
- SQL Server String Functions: A Practical GuideSQL Server provides over 30 built-in string functions that let you manipulate text data directly in T-SQL, covering…
- Excel Compare Dates to Today: Formulas and ExamplesTo compare a date in Excel with today, use the TODAY() function: for a date in A2, =A2=TODAY()…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.