Excel Formula for Matching Cells: VLOOKUP, XLOOKUP & More
In this article
Excel formulas for matching cells let you find and retrieve data from one range based on a lookup value in another. The core goal is to locate a specific value (like an ID or name) in one column and return a related value from a different column—critical for tasks like invoice matching, inventory checks, or merging datasets. No special tools are required beyond Excel itself (any modern version, including Microsoft 365, Excel 2021, or Excel 2019).
What You'll Need
- Microsoft Excel installed (any recent version)
- Two columns or tables with at least one shared field (e.g., Employee ID, Product Code)
- Clarity on which column contains your lookup value and which contains the return value
Step-by-Step
- Open your Excel workbook and ensure your data is organized in clean columns with no blank rows or columns in the middle of the dataset. For example, place lookup values in column A (e.g., A2:A100) and the corresponding return values in column B (e.g., B2:B100).
- Decide which formula to use. For most users, XLOOKUP is recommended (available in Excel 365 and Excel 2021+) because it is more flexible and forgiving than older functions like VLOOKUP. If you’re using an older version, use VLOOKUP instead.
- For XLOOKUP, click the cell where you want the result to appear, then type:
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode]). Replace each argument:- lookup_value: the cell containing the value you’re searching for (e.g., D2)
- lookup_array: the range where Excel should search (e.g., A2:A100)
- return_array: the range from which to pull the result (e.g., B2:B100)
- [if_not_found] (optional): what to show if no match is found—use
"Not found"or0for clarity
=XLOOKUP(D2, A2:A100, B2:B100, "No match") - Press Enter. Excel returns the matched value. Drag the fill handle (small square at the bottom-right of the cell) down to apply the formula to other rows.
- If you’re using VLOOKUP (for compatibility), click the result cell and type:
=VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup]). Key points:- lookup_value: same as above (e.g., D2)
- table_array: must include *both* the lookup column and the return column, with the lookup column on the left (e.g., A2:B100)
- col_index_num: the column number *within* the table_array to return—1 for the first column, 2 for the second, etc.
- [range_lookup]: always use
FALSEfor exact matches
=VLOOKUP(D2, A2:B100, 2, FALSE) - For multiple criteria (e.g., match both Name *and* Department), use XLOOKUP with concatenation:
=XLOOKUP(D2&E2, A2:A100&B2:B100, C2:C100, "Not found"), where D2 is Name, E2 is Department, A2:A100 is Name list, B2:B100 is Department list, and C2:C100 holds the return values.
Common Mistakes
- Using VLOOKUP when the lookup column isn’t the leftmost in the table—VLOOKUP only searches the first column of the table_array, so if your ID is in column B and you want to return column A, it won’t work without rearranging data or using INDEX/MATCH.
- Forgetting to lock ranges with dollar signs (e.g., $A$2:$A$100) when dragging formulas down; without locking, the range shifts and breaks the lookup.
- Ignoring leading/trailing spaces or inconsistent formatting (e.g., "123" vs. 123). Use
=TRIM(CLEAN(A2))to clean data before matching. - Assuming case sensitivity—Excel’s lookup functions are not case-sensitive by default. "JOHN" and "john" both match.
- Using approximate match (setting range_lookup to TRUE or omitting it) when an exact match is needed—this can return incorrect values if data isn’t sorted.
Tips
- Use structured references if your data is in an Excel Table (press Ctrl+T to convert). Instead of A2:B100, use —this auto-adjusts as rows are added.
- Combine XLOOKUP with IFERROR for cleaner error handling:
=IFERROR(XLOOKUP(D2, A2:A100, B2:B100, "No match"), "Missing data"). - For large datasets, XLOOKUP is faster and more reliable than VLOOKUP or INDEX/MATCH combos due to its built-in binary search and error resilience.
- Store lookup values in separate cells or named ranges. Define a name like
EmployeeTablefor A2:B100, then use=XLOOKUP(D2, EmployeeTable, ...)for readability and easier updates. - Test with a small dataset first (e.g., 5 rows) before applying to hundreds of rows to catch errors early.
Troubleshooting
If your formula returns an error or unexpected result, follow these checks in order:
- #N/A error: This means no match was found. Verify the lookup value exists in the lookup range—check for hidden spaces (use
=LEN(A2)to compare lengths), different data types (text vs. number), or case-insensitive mismatches (though Excel ignores case, ensure spelling matches exactly). - #VALUE! or #REF! error: Likely caused by incorrect argument types or invalid ranges. Ensure lookup_array and return_array have the same number of rows and no merged cells. Confirm col_index_num in VLOOKUP is at least 1 and within the table’s column count.
- Wrong value returned: If using VLOOKUP, double-check [range_lookup] is set to FALSE for exact matches. Also, confirm the table_array includes *all* necessary columns and the return column index is correct.
- Formula works for some rows but not others: Inspect the problematic cells for invisible characters. Select the cell, go to Home > Find & Select > Go To Special > Blanks to find empty cells, or use the Text to Columns feature (Data > Text to Columns > Finish) to refresh formatting.
- Using an older Excel version without XLOOKUP: Replace XLOOKUP with INDEX/MATCH:
=INDEX(return_array, MATCH(lookup_value, lookup_array, 0)). Ensure the0in MATCH forces an exact match.
Frequently Asked Questions
Can Excel match cells across different worksheets?
Yes. Reference the other sheet in the formula. For XLOOKUP:=XLOOKUP(D2, Sheet2!A2:A100, Sheet2!B2:B100). Ensure sheet names with spaces are wrapped in single quotes: 'Sales Data'!A2:A100.
How do I match partial text, like finding "Apple" in "Apple Inc."?
Use wildcards with XLOOKUP. Set match_mode to 2:=XLOOKUP("*" & D2 & "*", A2:A100, B2:B100, "Not found", 2). This finds partial matches. In VLOOKUP, use =VLOOKUP("*" & D2 & "*", A2:B100, 2, FALSE), but note it only works if the lookup value isn’t empty.
What if my lookup column contains duplicates?
All lookup functions return only the *first* match. To get the last match, use XLOOKUP with search_mode set to -1 (reverse search):=XLOOKUP(D2, A2:A100, B2:B100, "", 0, -1). For all matches, consider using FILTER (Excel 365): =FILTER(B2:B100, A2:A100=D2).
Can I match two values at once, like ID + Date?
Yes. Concatenate the criteria in both the lookup and search ranges. Example:=XLOOKUP(D2&E2, A2:A100&B2:B100, C2:C100), where D2=ID, E2=Date, A2:A100=ID list, B2:B100=Date list, C2:C100=return values. Alternatively, use FILTER: =FILTER(C2:C100, (A2:A100=D2)*(B2:B100=E2)).
Why does my formula show #NAME?
This usually means Excel doesn’t recognize a function name—likely because you’re using XLOOKUP in Excel 2019 or earlier, where it’s unavailable. Switch to INDEX/MATCH or update Excel. Also check for typos (e.g., "XLOKUP") or missing equals sign.How do I prevent #N/A errors from cluttering my sheet?
Wrap your formula in IFERROR:=IFERROR(XLOOKUP(...), "") for blank results or =IFERROR(XLOOKUP(...), "Pending") for user-friendly messages. This keeps reports clean and avoids confusion during analysis.