Matching data in Excel connects two separate lists to find matches or retrieve information from one list into another. It is used to clean up data, merge customer lists, or pull specific details like prices or names into a new spreadsheet. The most reliable method for this is using the XLOOKUP function. Another common option is INDEX and MATCH. Both functions work in all modern versions of Excel for Windows, Mac, and the web, though older versions may only support the older VLOOKUP function.
What You'll Need
- A computer with Microsoft Excel installed (2019, 2021, or Microsoft 365 are the versions where XLOOKUP was introduced; versions 2016 and earlier use VLOOKUP or INDEX/MATCH).
- Two sets of data in separate columns or tables. One set will be the "lookup" (the source of the information you want to find), and the other will be the "lookup value" (the item you are searching for).
- Basic familiarity with selecting cells and typing formulas.
Step-by-Step
- Set up your data. Place your "lookup values" in one column. This is the unique identifier you know, such as an Order ID, Employee Name, or Product SKU. Place the data you want to retrieve in a separate column next to it. For example, Column A contains Order IDs, and Column B contains the names of the customers who placed those orders. You will likely want to add a new empty column to the right of your lookup values (Column C) to place your formula.
- Identify the lookup range. Determine the range of cells that contains the data you want to retrieve. In our example, this is Column B (Customer Names). Click into the first empty cell in the column where you want the result to appear (Cell C2). This cell will hold the formula that looks up the value in Cell A2.
- Start the XLOOKUP formula. Type
=XLOOKUP(into the cell. The function will prompt you with a tooltip showing the required arguments: lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode]. - Enter the lookup value. The first argument is lookup_value. Click on the cell that contains the first item you want to match. In our example, click on Cell A2 (the first Order ID). This tells Excel to find a match for the value in A2. Type a comma to move to the next argument.
- Enter the lookup range. The second argument is lookup_array. This is the column where Excel should search for the value you selected in the previous step. Click and drag to select the entire column of unique identifiers (in our example, Column A). Do not include the header row. Close the parentheses for this argument, or just type a comma.
- Enter the return range. The third argument is return_array. This is the column containing the data you want to see in your new list. Click and drag to select the column of values you want to retrieve (in our example, Column B). Do not include the header row. Close the parentheses for the entire function and press Enter.
- Copy the formula down. Once the formula works for the first row, click on that cell again to see a small square handle in the bottom-right corner. Click and drag this handle down to the bottom of your data list. Excel will automatically adjust the row numbers for each subsequent item, filling the column with the matched data.
Using INDEX and MATCH (Alternative Method)
If you are using a very old version of Excel that does not support XLOOKUP, you can achieve the same result with two functions combined. The logic is slightly more complex but offers similar flexibility. The INDEX function gets a value from a range, and the MATCH function finds the position of a value within a range.
- Click into the cell where you want the result to appear.
- Type
=INDEX(return_range, MATCH(lookup_value, lookup_range, 0)). - Replace
return_rangewith the column of data you want to retrieve (e.g., B2:B100). - Replace
lookup_valuewith the cell containing the item you are searching for (e.g., A2). - Replace
lookup_rangewith the column where the item exists (e.g., A2:A100). - Press Enter to complete the formula. Note the comma between the two functions and the 0 at the end, which tells Excel to look for an exact match.
Common Mistakes
- Leaving spaces or formatting differences. The most common reason for a match to fail is hidden characters. If Column A has "John Doe" and Column B has "John Doe ", Excel will not see them as a match. Use the TRIM function to remove extra spaces around text (e.g.,
=TRIM(A2)) or use the Find & Replace feature (Ctrl+H) to replace spaces with nothing. - Text vs. Numbers. If the lookup value is a number (like 101) but the data you are searching in is formatted as text, the match will fail. You can fix this by selecting the column, going to the Home tab, clicking the Number Format dropdown, and choosing "Number". Alternatively, use the VALUE function to convert text to a number.
- Mismatched ranges. In the XLOOKUP function, the lookup range and the return range must be of the same height. If you select Column A (100 rows) for the lookup but Column B (50 rows) for the return, you will get an error. Select the entire columns, not just the populated rows.
- Using VLOOKUP with left columns. The VLOOKUP function can only look to the right of the lookup value. If your data is arranged with the lookup value to the right of the information you need, VLOOKUP cannot retrieve it. This is a primary reason to switch to XLOOKUP or INDEX/MATCH.
Tips
- Make the lookup value unique. For a match to be found, the item you are searching for must appear only once in your lookup range. If an item appears twice, Excel will return the match for the first one it finds. Double-check your data to ensure there are no duplicates in the column you are searching.
- Use absolute references. If you plan to move the formula around or apply it to multiple sheets, it is safer to use absolute references. In the formula bar, press F4 after selecting your ranges. This will turn cell references like A2 into
$A$2. This prevents Excel from shifting the reference when you copy the formula to another row or sheet. - Handle errors gracefully. If a match is not found, you will see
#N/A. You can customize this by adding a fourth argument to XLOOKUP. For example,=XLOOKUP(..., "Not Found")will display the text "Not Found" instead of the error code. This is helpful for quickly spotting missing data. - Sort your data. While XLOOKUP does not require sorting, sorting your lookup column makes it easier to debug. If you are using MATCH with 0 (exact match) and it fails, it is often because the data is not sorted correctly or contains errors.
Troubleshooting
When the formula returns #N/A, it means Excel could not find the lookup value in the search range. Follow these steps to identify the problem.
1. Check for hidden characters. Select the cell with the lookup value and the matching cell in the search range. Compare them visually. If they look the same, look at the formula bar for both cells. If one has an invisible space or a non-breaking space, the match will fail. Select the cells, go to the Home tab, and click the "Find & Select" button, then choose "Replace". Leave the "Find what" field blank and the "Replace with" field blank, then click "Replace All" to clear all spaces.
2. Verify data types. If your lookup value is a number but the search column contains numbers stored as text, the match will fail. You can test this by subtracting 0 from a cell. If the result is still a number, it was stored as a number. If the result is a date or an error, it is stored as text. Select the column, go to Data > Text to Columns > Finish to convert it.
3. Check for spelling errors. Typos are the most common cause of failed matches. Ensure that the lookup value is spelled exactly as it appears in the search range, including capitalization (unless you have used the MATCH_MODE argument to ignore case).
4. Verify the range. Ensure that you have selected the entire column for the search range. If you accidentally select only the header row or a subset of the data, the formula will not find the item.
5. Check for unmerged cells. If the lookup value and the search range are in the same cell range but one cell is merged with another, this can cause calculation errors. Unmerge the cells and ensure that each piece of data resides in its own individual cell.
Frequently Asked Questions
What is the difference between VLOOKUP and XLOOKUP?
VLOOKUP searches for a value in the first column of a range and returns a value in a specified column to the right. XLOOKUP can search any column and return a value from any column, including to the left of the search value. XLOOKUP is also more robust and easier to use because it does not require you to count columns to determine which one to return.
Why does my Excel say "#VALUE!" instead of a match?
A #VALUE! error usually means there is a problem with the data types within the arguments. For example, if you try to match a text string against a number, or if one of your ranges contains text where a number is expected, the formula will fail. Check that both the lookup value and the data in the range are of the same type.
Can I match data across different worksheets?
Yes. You can reference cells or ranges from another sheet by typing the sheet name followed by an exclamation mark (e.g., =XLOOKUP(A2, 'Sheet2'!A:A, 'Sheet2'!B:B)). Ensure the single quotes are included if the sheet name contains spaces.
How do I match data if there are duplicates in the list?
If there are duplicates in your lookup column, Excel will return the first match it finds. To get the last match, you can use the [search_mode] argument in XLOOKUP and set it to -1, which searches from the bottom of the range up.
Does the order of the data matter?
For standard XLOOKUP and VLOOKUP, the order does not matter. The function will scan the entire range you provide to find the first match. However, for the INDEX/MATCH combination with an exact match (MATCH mode 0), the data should ideally be sorted, though it is not strictly required for the formula to work.