Matching Data in Excel Sheets: A Complete Guide
In this article
Matching data in Excel allows you to compare two different lists to find common values, identify missing entries, or pull corresponding information from one table into another. This is most commonly achieved using the XLOOKUP function (in modern versions of Excel) or the VLOOKUP function (in older versions), though conditional formatting and the MATCH function are also powerful tools for simple comparisons. By mastering these methods, you can automate the process of auditing lists, merging customer databases, or reconciling financial records without manual searching.
What You'll Need
- Microsoft Excel installed on your computer (version 2021 or Microsoft 365 is recommended for XLOOKUP access).
- Two sets of data that share a "Unique Identifier"—a common piece of information like an Email Address, Product ID, or Employee Number that appears in both sheets.
- Clean data: Ensure there are no trailing spaces or hidden characters in your matching columns.
Step-by-Step
Depending on your goal, you will use different methods. Below are the three most effective ways to match data, ranging from simple visual checks to advanced data retrieval.
Method 1: Using XLOOKUP (Best for pulling data from one sheet to another)
XLOOKUP is the modern standard for matching. It looks for a value in one column and returns a value from the same row in another column.
- Open the sheet where you want the matched data to appear.
- Click in the empty cell where you want the result to be displayed.
- Type
=XLOOKUP(. - Select the Lookup Value: Click on the cell in your current sheet that contains the unique ID you are searching for (e.g., cell A2). Type a comma.
- Select the Lookup Array: Navigate to the second sheet and highlight the entire column that contains the unique IDs. Type a comma.
- Select the Return Array: While still on the second sheet, highlight the column that contains the information you want to bring back (e.g., the "Price" or "Email" column).
- Close the parenthesis
)and press Enter. - Hover your mouse over the bottom-right corner of the cell until a small cross appears, then double-click or drag down to apply the formula to the rest of the column.
Method 2: Using VLOOKUP (For older versions of Excel)
If you are using an older version of Excel that does not support XLOOKUP, VLOOKUP is the alternative. Note that VLOOKUP requires the unique identifier to be in the leftmost column of your data range.
- Click the cell where you want the result.
- Type
=VLOOKUP(. - Select the unique ID cell in your current sheet and type a comma.
- Go to the second sheet and highlight the entire table range, starting from the unique ID column and extending to the column containing the data you want. Type a comma.
- Enter the Column Index Number: Count the columns in your highlighted range from left to right. If the data you want is in the third column of the range, type
3. Type a comma. - Set Exact Match: Type
FALSEto ensure Excel only matches exact values. - Close the parenthesis
)and press Enter.
Method 3: Using Conditional Formatting (Best for visual comparison)
Use this method if you don't need to move data, but simply want to see which items in List A also appear in List B.
- Highlight the column of data in your first sheet.
- Go to the Home tab on the top ribbon.
- Click Conditional Formatting > New Rule.
- Select Use a formula to determine which cells to format.
- In the formula box, type:
=COUNTIF(Sheet2!$A:$A, A1)>0(ReplaceSheet2!$A:$Awith the range of the second list andA1with the first cell of your current selection). - Click the Format button, choose a fill color (like green), and click OK.
- Click OK again. All cells in your first list that also exist in the second list will now be highlighted.
Common Mistakes
Matching errors are rarely caused by the formula itself, but rather by the quality of the data. Watch out for these frequent pitfalls:
- Trailing Spaces: A cell containing "Apple " (with a space) will not match a cell containing "Apple". This is the most common cause of
#N/Aerrors. - Data Type Mismatch: If one sheet stores IDs as "Numbers" and the other stores them as "Text", Excel will treat them as different values even if they look identical.
- Absolute vs. Relative References: When using VLOOKUP or MATCH, forgetting to lock your range with dollar signs (e.g., using
A1:B10instead of$A$1:$B$10) causes the search area to shift downward as you drag the formula, leading to missing matches. - Wrong Column Index: In VLOOKUP, counting the columns incorrectly will result in the formula returning data from the wrong field.
Tips
- Use Tables: Convert your data ranges into official Excel Tables (Ctrl + T). This makes your formulas dynamic, meaning if you add new rows to your data, the matching formulas will update automatically without needing to be dragged down.
- The TRIM Function: If you suspect trailing spaces, create a helper column and use
=TRIM(A2)to remove all leading and trailing whitespace before attempting to match. - Handling #N/A: To avoid seeing
#N/Afor items that don't have a match, wrap your formula in IFERROR. For example:=IFERROR(XLOOKUP(...), "No Match Found"). - Data Validation: Use the "Remove Duplicates" tool (Data tab > Remove Duplicates) on your unique identifier columns before matching to ensure you aren't getting skewed results from repeated entries.
Troubleshooting
If your formulas are returning errors or incorrect results, follow these steps in order:
- Check for hidden spaces: Select a cell that should match but isn't. Look at the formula bar; if the cursor blinks a few spaces away from the last character, use the TRIM function.
- Verify Data Types: Select the columns in both sheets. Go to the Home tab and check the Number Format dropdown. If one is "General" and the other is "Text", change both to "General" and then re-enter the data or use the "Text to Columns" tool to convert them.
- Check the Range: Ensure your lookup array covers the entire dataset. If your data extends to row 1000 but your formula only references
$A$1:$A$500, half of your data will be ignored. - Test a Single Match: Manually type a value you know exists in both sheets into a blank cell and run the formula against that specific value to see if the issue is with the formula logic or the data itself.
Frequently Asked Questions
Can I match data across two different Excel files?
Yes. When selecting your lookup array, simply switch to the other open Excel window and highlight the range. Excel will automatically add the file name to the formula path.
What is the difference between XLOOKUP and VLOOKUP?
XLOOKUP is more flexible; it can look to the left of the search column, it defaults to an exact match, and it doesn't require you to count column numbers.
How do I find values that are NOT in both lists?
Use the conditional formatting method described above, then use the "Filter by Color" option to show only the cells that remain unhighlighted.
Does Excel matching work with partial matches?
Yes. XLOOKUP and VLOOKUP support wildcards. Using an asterisk (*) in your lookup value allows you to find matches that start with or contain a specific string of text.
Why is my VLOOKUP returning the wrong row?
This usually happens because the fourth argument is set to TRUE (Approximate Match) instead of FALSE. Ensure your formula ends with , FALSE) to force an exact match.