Yes, you can combine VLOOKUP and HLOOKUP in a single formula to look up a value that requires matching both a row label and a column label. The most common approach nests HLOOKUP inside VLOOKUP (or vice versa) so that one function supplies the column index number the other needs, effectively performing a two-way lookup.
What VLOOKUP and HLOOKUP Each Do
VLOOKUP searches vertically down the first column of a table and returns a value from a column you specify. HLOOKUP searches horizontally across the first row and returns a value from a row you specify. Both use the same logic: find a match in the lookup row/column, then step over (or down) a set number of positions to grab the result.
In Excel for Microsoft 365, the syntax is:
=VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])=HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup])
The range_lookup argument is FALSE for an exact match or TRUE (or omitted) for an approximate match. For most combination uses, you will want FALSE to avoid unexpected results.
Why Combine Them? The Two-Way Lookup Problem
A single VLOOKUP can only find a value based on one row label. A single HLOOKUP can only find a value based on one column label. Real data often has a matrix: months across the top, product names down the side, and sales numbers in the middle. To get the sales for “Product A” in “March,” you need to match both the row and the column. That is exactly the problem the combination solves.
For example, suppose you have a table with product names in A2:A10, months in B1:M1, and sales figures in B2:M10. To find Product A’s March sales, you need the row number for “Product A” and the column number for “March”. The combination formula does this in one step.
How to Nest HLOOKUP Inside VLOOKUP
The standard pattern is to use HLOOKUP to find the column number, then feed that number into VLOOKUP as the col_index_num. Here is the layout:
- A1:M10 is the whole table.
- Product names are in A2:A10.
- Month names are in B1:M1.
- Your lookup product is in cell A12.
- Your lookup month is in cell B12.
The formula in C12 would be:
=VLOOKUP(A12, A1:M10, HLOOKUP(B12, A1:M1, 1, FALSE), FALSE)
How it works: HLOOKUP searches for the month name in row 1 and returns the position of that month within the range A1:M1. Since A1 is the first column, “March” in C1 would return 3. That 3 becomes the column index for VLOOKUP, which then finds “Product A” in column A and returns the value from the 3rd column (C), which is March’s sales.
Note that the HLOOKUP range (A1:M1) starts at the same column as the VLOOKUP table (A1) so the column numbers line up. If you start HLOOKUP at B1, you would need to add 1 to the result.
Alternative: Nest VLOOKUP Inside HLOOKUP
You can reverse the nesting. Use VLOOKUP to find the row number, then feed that into HLOOKUP as the row_index_num. This is less common because HLOOKUP is generally used less, but it works identically.
Using the same table layout, the formula would be:
=HLOOKUP(B12, A1:M10, VLOOKUP(A12, A1:A10, 1, FALSE), FALSE)
Here, VLOOKUP finds “Product A” in A1:A10 and returns its row position (e.g., row 3). HLOOKUP then finds “March” in row 1 and returns the value from the 3rd row of the table, which is March’s sales for Product A. This approach is a bit trickier because the VLOOKUP range (A1:A10) must return the row number relative to the HLOOKUP table’s first row. If your table starts at row 2, you need to adjust.
When to Use INDEX and MATCH Instead
The VLOOKUP/HLOOKUP combination works, but it is fragile. If you insert a column or row, the column index numbers shift and the formula breaks. A more robust solution is to use INDEX and MATCH together, which handles both dimensions without nesting two lookup functions.
The equivalent INDEX/MATCH formula for the same example is:
=INDEX(B2:M10, MATCH(A12, A2:A10, 0), MATCH(B12, B1:M1, 0))
This returns the value at the intersection of the row where Product A is found and the column where March is found. It is easier to read, does not break when you add columns, and works in all Excel versions. For most users, this is the better choice. The combination of VLOOKUP and HLOOKUP is mainly useful when you are constrained to using only those two functions (for example, in older workbooks or compatibility scenarios).
Common Errors and How to Fix Them
The most frequent error is #N/A, which means one of the lookups did not find a match. Check that the product name and month are spelled exactly as in the table, including spaces. Another error is #REF!, which appears when the column or row index number is larger than the table width or height. This usually happens when the HLOOKUP returns a position that counts from a different starting column than the VLOOKUP table.
A third issue is approximate match problems. If you omit FALSE or use TRUE, Excel may return a wrong but close value. Always use FALSE for exact text matches. Also, if your table has merged cells or blank rows, both functions can misbehave. Keep the lookup row and column free of blanks and merged cells.
Frequently Asked Questions
Can I combine VLOOKUP and HLOOKUP for a 3D lookup? No, the combination only handles two dimensions. For three or more, you would need to nest multiple INDEX/MATCH functions or use a helper column that concatenates keys.
Does this work in Google Sheets? Yes, both VLOOKUP and HLOOKUP exist in Google Sheets with the same syntax, so the combination works there. However, Google Sheets also has XLOOKUP (since 2022) which can do two-way lookups more simply with a single function.
What if my table has headers on both rows and columns? That is exactly the scenario described above. Just make sure the HLOOKUP range includes the header row and the VLOOKUP range includes the header column, and adjust the index numbers accordingly.
Is there a limit to how many times I can nest these? Excel allows up to 64 levels of nesting for functions, but practically you should never nest more than two or three. Beyond that, the formula becomes unreadable and error-prone.
Why does my formula return the wrong value even though there is no error? This usually means you used TRUE for approximate match, or your lookup ranges are not aligned. Double-check that the HLOOKUP range starts at the same column as the VLOOKUP table’s first column, and that you are using FALSE for exact matches.
Practical Example with Real Numbers
Consider a small sales table:
- A1: (blank), B1: Jan, C1: Feb, D1: Mar
- A2: Widget, B2: 100, C2: 150, D2: 200
- A3: Gadget, B3: 300, C3: 250, D3: 400
To find Gadget’s February sales, put “Gadget” in A5 and “Feb” in B5. The formula =VLOOKUP(A5, A1:D3, HLOOKUP(B5, A1:D1, 1, FALSE), FALSE) returns 250. HLOOKUP finds “Feb” in row 1, returns 3 (since A1 is column 1, B1 is 2, C1 is 3), and VLOOKUP uses 3 as the column index, finding “Gadget” in row 3 and returning the value from column C, which is 250.
Related
- How to Select a Cell and Everything Below It in Excel
- SQL Difficult Queries: Real-World Examples & Solutions
- Switch Desktop Shortcut: How to Create & Use It
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Excel Formula for High and Low Values: MIN and MAXIn Excel, use =MIN(B2:B10) to find the lowest number in a range and =MAX(B2:B10) to find the highest.…
- Excel TEXTJOIN: Concatenate Text with SeparatorsThe fastest way to concatenate text in Excel is the TEXTJOIN function, which combines multiple ranges or strings…
- Excel INDEX MATCH Returning Wrong Value? FixesIf your Excel INDEX MATCH formula is returning the wrong value, the most common causes are mismatched row/column…
- String Functions in SQL: Common Uses, Syntax, and ExamplesSQL string functions work with text: they can join values, change letter case, remove unwanted spaces, extract part…
- Grading in Excel Using IF: Formulas and ExamplesTo assign letter grades in Excel, put each numeric score in column B and enter a nested IF…
- NPV vs PV in Excel: Formulas and Key Differences ExplainedIn Excel, use NPV to discount a series of periodic cash flows, but keep a time-zero investment outside…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.