Yes, you can create a comparison in Excel using functions like VLOOKUP and XLOOKUP to join two datasets, or by using the Inquire or Compare Files add-ins to audit workbook differences. This guide focuses on using standard lookup functions and conditional formatting for the most common needs, as these work across all modern versions of Excel.

What You'll Need

  • A computer with Microsoft Excel installed (2016 or later recommended for XLOOKUP).
  • Two sets of data or data files to compare. These are often called "source" and "target" lists, or "database" and "report" lists.
  • A basic understanding of Excel ranges (e.g., A1:B10).
  • Optional: The Inquire add-in for auditing workbook structure, which is available through the File > Options > Add-ins menu.

Step-by-Step

The most common comparison task is identifying which items in one list exist in another. For example, comparing a list of purchased items against a list of approved items, or comparing last month's sales against this month's sales to find new customers.

  1. Prepare your data. Ensure your data is in a single column for each list. The lists should share a common identifier, such as a Product ID, Customer Name, or Invoice Number. Do not include headers in the data range when selecting it for the formula. For example, if your data is in A2:A100, select A2:A100.
  2. Open the Excel sheet. Open the workbook containing the first list. This will be the list you are searching within. If you are comparing two different files, open both workbooks side-by-side.
  3. Enter the lookup function. Click the cell in the column next to your first list (the list you are checking). Type the function name. For the most robust method in current versions of Excel, type =XLOOKUP. For older versions, type =VLOOKUP.
  4. Define the lookup value. The first argument of the function is the value you are looking for. Click on the cell in your first list that corresponds to the first item you want to check. Excel will insert the cell reference (e.g., A2). Press F4 to make the reference absolute if you plan to copy the formula down a column; this locks the column and row (e.g., $A$2).
  5. Define the lookup array. The second argument is the array or list to search. Click on the header of the column in the second list that contains the matching data. For VLOOKUP, this is the column where the match is found. For XLOOKUP, this is the array containing the values to compare against. Press F4 to make it absolute (e.g., $D$2:$D$1000).
  6. Define the return array (optional). The third argument is what to return if a match is found. For VLOOKUP, this is the column to the right of the match. For XLOOKUP, this is the column in the lookup array that contains the result you want. If you just want to know if the item exists, you can return a specific value like "Yes" or "Match".
  7. Define the match mode. The fourth argument determines how Excel finds the match. Type 0 for exact match. This is required for most comparisons. Type -1 for exact match or next smaller value, and 1 for exact match or next larger value. For standard list comparison, use 0.
  8. Define the search mode. The fifth argument is the search direction. Type 1 to search from top to bottom (default). Type -1 to search from bottom to top. For most lists, this is left as the default.
  9. Complete the formula and copy it. Press Enter. Excel will return the result (e.g., the value from the second list, or an #N/A error if no match is found). Double-click the fill handle (the small square at the bottom-right corner of the cell) to apply the formula to the entire column.
  10. Interpret the results. Look for #N/A errors. These indicate that the item in the first list was not found in the second list. This is the core of your comparison. You can filter for these errors to see only the items that are different.

Common Mistakes

When creating comparisons, errors usually stem from data formatting or formula construction. The most frequent issues are mismatched data types and incorrect range selection.

  • Text vs. Numbers: One of the most common reasons for a failed comparison is that one list contains numbers formatted as text (e.g., "123") and the other contains actual numbers (123). Excel sees these as different values. To fix this, use the VALUE function to convert text to numbers, or use the NUMBERVALUE function for more complex formatting.
  • Extra Spaces: Invisible spaces can prevent a match. For example, "Item A" and "Item A " are not the same. Use the TRIM function to remove leading, trailing, and multiple spaces from a cell (e.g., =TRIM(A2)).
  • Order of Arguments: In VLOOKUP, the lookup column must be to the right of the return column. In XLOOKUP, the order of the lookup and return arrays does not matter. This is a major advantage of using XLOOKUP.
  • Not Locking the Lookup Array: If you do not make the lookup array reference absolute (using $), copying the formula down will shift the range. This will cause the formula to check against the wrong data, leading to incorrect results.

Tips

  • Use Conditional Formatting: Highlight the differences visually. Select the column with your results. Go to Home > Conditional Formatting > Highlight Cells Rules > Equal To. Set the rule to #N/A and choose a color (e.g., Red). This will instantly show you which items are missing from the comparison list.
  • Filter for Errors: Instead of manually scanning for #N/A errors, use the Filter. Click the filter arrow on the column header. In the search box, type #N/A. Excel will filter only the rows that contain this error, allowing you to see the differences in isolation.
  • Use the Inquire Add-in: For comparing entire workbooks or checking for broken links, use the Inquire add-in. Go to File > Options > Add-ins > Manage Excel Add-ins > Go. Check the box for Inquire and click OK. This tool provides a detailed report on workbook structure and differences.
  • Sort Your Data: Before running a comparison, sort both lists by the key identifier. This makes it easier to spot discrepancies and can help you spot data entry errors like missing rows.
  • Check for Duplicates: Before comparing, use the Remove Duplicates feature (Data > Remove Duplicates) to ensure you are comparing unique records. Comparing lists with duplicates can lead to misleading results.

Troubleshooting

If your comparison is not working as expected, check these common issues in this order.

  • Check for #N/A errors: If you are using the function to find items in the second list, an #N/A error means the item was not found. If you are using the function to find items in the first list, an #N/A error means the item was not found in the second list. This is the correct behavior for a comparison.
  • Check the Data Types: Ensure that you are comparing apples to apples. If one list is text and the other is a number, the comparison will fail. Use TYPE or ISTEXT functions to check the data type of a cell.
  • Check for Extra Spaces: If you see #N/A for a value that looks correct, there may be hidden spaces. Use the LEN function to check the length of the string. A string with extra spaces will have a longer length than the same string without spaces.
  • Check the Range: Ensure that the lookup array includes all the data you want to compare against. If the range is too small, some items will not be found. If the range is too large, the formula may be checking against empty cells.
  • Restart Excel: If you are experiencing strange behavior, such as formulas not updating or errors appearing inexplicably, try restarting Excel. Sometimes, Excel's calculation engine can get stuck.
  • Check for Merged Cells: Merged cells can cause issues with range selection and formula copying. Avoid merging cells in your data area. If you must merge cells, use the "Merge & Center" option rather than the "Merge Across" option.

Frequently Asked Questions

Why is my VLOOKUP not finding a match?

This is usually due to text formatting issues, such as one list containing numbers and the other text, or hidden spaces. Ensure data types match and use the TRIM function to remove spaces.

What is the difference between XLOOKUP and VLOOKUP?

XLOOKUP is more robust because it allows you to search in any column and return a value from any column, regardless of their order. It also handles errors more gracefully than VLOOKUP.

How do I compare two columns and highlight the differences?

Use Conditional Formatting with a rule set to #N/A. This will highlight the cells in your comparison column that are not found in the second list.

Can I compare two different Excel files?

Yes, you can open both files and use the lookup function to compare them. However, for a more detailed comparison of entire workbooks, use the Inquire add-in.

What does the 0 argument in XLOOKUP do?

The 0 argument tells Excel to look for an exact match. This is the standard setting for most comparisons.

How do I handle case sensitivity in comparisons?

Excel's standard lookup functions are not case-sensitive. To perform a case-sensitive comparison, you can use the EXACT function combined with IF to check for matches.