Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Comparing Data in Two Excel Workbooks: Step-by-Step Guide

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Comparing data across two Excel workbooks is best achieved using the VLOOKUP or XLOOKUP functions to find discrepancies, or by using the View Side by Side feature for manual visual audits. These methods allow you to identify missing records, spot value changes between versions of a file, and ensure data integrity when merging datasets. To start, ensure both workbooks are open in the same instance of Excel and that the data you are comparing is organized in tables or structured ranges with a unique identifier, such as an ID number or email address, to prevent misalignment.

What You'll Need

  • Two Excel workbooks (.xlsx or .xls format) containing the datasets to be compared.
  • A unique identifier column (Primary Key) present in both files (e.g., Employee ID, SKU, or Order Number).
  • A third "Comparison" workbook or a new sheet within one of the existing workbooks to house the results.
  • Basic familiarity with Excel cell referencing and formula syntax.

Step-by-Step

Depending on your goal—whether you need a quick visual check or a detailed automated report—choose one of the following methods. Note that menu labels may differ slightly depending on your version of Excel or operating system.

Method 1: Visual Comparison (Side by Side)

Use this method for small datasets where you need to manually spot differences without writing formulas.

  1. Open both Excel workbooks that you wish to compare.
  2. Go to the View tab on the ribbon.
  3. In the Window group, click View Side by Side. Excel will automatically tile the two windows.
  4. Ensure Synchronous Scrolling is enabled (this is usually on by default after clicking View Side by Side). This allows you to scroll down in one workbook and have the other scroll simultaneously, keeping the rows aligned.
  5. Manually scan the columns to identify differences. If the rows are not in the same order, this method will not be effective; you must sort both sheets by the same column first.

Method 2: Using XLOOKUP for Automated Comparison

XLOOKUP is the most efficient way to find if a value in Workbook A exists in Workbook B and if the corresponding data matches. This is the preferred method for large datasets.

  1. Open both workbooks. Let's call them Workbook_A.xlsx and Workbook_B.xlsx.
  2. In Workbook_A, create a new column titled "Comparison Result" next to the data you want to verify.
  3. In the first empty cell of this new column, type the following formula: =XLOOKUP(A2, [Workbook_B.xlsx]Sheet1!$A:$A, [Workbook_B.xlsx]Sheet1!$B:$B, "Not Found").
  4. Breakdown of this formula: A2 is the unique ID in Workbook A; [Workbook_B.xlsx]Sheet1!$A:$A is the column in the second book containing the IDs; [Workbook_B.xlsx]Sheet1!$B:$B is the column containing the value you want to retrieve for comparison.
  5. Press Enter. If the ID exists in Workbook B, Excel will return the value from Workbook B. If it does not exist, it will return "Not Found".
  6. To see if the values actually match, wrap the XLOOKUP in an IF statement: =IF(B2=XLOOKUP(A2, [Workbook_B.xlsx]Sheet1!$A:$A, [Workbook_B.xlsx]Sheet1!$B:$B), "Match", "Difference").
  7. Drag the fill handle (the small square at the bottom-right of the cell) down to apply the formula to all rows in your dataset.

Method 3: Using Conditional Formatting to Highlight Differences

This method is useful when you have two identical sheets in one workbook (or have copied a sheet from Workbook B into Workbook A) and want to highlight every cell that differs.

  1. Copy the data from Workbook B and paste it into a new sheet (Sheet2) in Workbook A.
  2. Highlight the entire data range in Sheet1.
  3. Go to the Home tab, click Conditional Formatting, and select New Rule.
  4. Select Use a formula to determine which cells to format.
  5. In the formula box, enter: =A1<>Sheet2!A1 (assuming your data starts at cell A1).
  6. Click the Format button, go to the Fill tab, and choose a bright color (like red or yellow) to highlight discrepancies.
  7. Click OK. Every cell in Sheet1 that does not exactly match the corresponding cell in Sheet2 will now be highlighted.

Common Mistakes

  • Ignoring Leading/Trailing Spaces: One of the most common reasons for a "Difference" result when data looks identical is the presence of invisible spaces. "Apple" and "Apple " are treated as different values by Excel. Use the TRIM() function to clean your data before comparing.
  • Data Type Mismatch: If one workbook stores IDs as "Text" and the other stores them as "Numbers", XLOOKUP and VLOOKUP will return "Not Found" even if the numbers look the same. Ensure both columns are formatted as the same data type.
  • Unsorted Data in Visual Comparison: Attempting to use Side by Side scrolling without sorting both sheets by the same unique identifier leads to comparing the wrong rows, resulting in false positives for differences.
  • Absolute vs. Relative References: When writing comparison formulas, forgetting to use dollar signs (e.g., using A:A instead of $A:$A) can cause the lookup range to shift as you drag the formula down, leading to incorrect results.

Tips

  • Convert to Tables: Press Ctrl + T to turn your data ranges into official Excel Tables. This makes your formulas dynamic, meaning if you add new rows to your data, the comparison formulas will automatically extend to include them.
  • Use a Helper Column: If you need to compare multiple columns (e.g., First Name, Last Name, and DOB), create a "Helper Column" that concatenates these values using =A2&B2&C2. Compare these combined strings rather than running five separate XLOOKUPs.
  • Freeze Panes: When doing manual comparisons, go to View > Freeze Panes > Freeze Top Row. This ensures you always know which column you are looking at as you scroll through thousands of rows.
  • Filter by Color: After using Conditional Formatting to highlight differences, use the Filter tool (Ctrl + Shift + L) and select Filter by Color to quickly isolate and review only the cells that need correction.

Troubleshooting

If your comparison is not producing the expected results, follow these steps in order:

  1. Check for #N/A Errors: An #N/A error in a lookup formula means the unique identifier was not found in the target workbook. Double-check that the ID actually exists in the other file and that there are no typos.
  2. Verify Workbook Links: If you see a warning about "Linked Workbooks" when opening the file, click Enable Content. If the formulas show #REF!, the second workbook may have been moved or renamed. Go to Data > Edit Links to update the source path.
  3. Clear Formatting: If Conditional Formatting is acting erratically, go to Conditional Formatting > Clear Rules > Clear Rules from Entire Sheet and re-apply the formula.
  4. Check Calculation Settings: If the formulas aren't updating when you change data, go to the Formulas tab, click Calculation Options, and ensure Automatic is selected.

Frequently Asked Questions

Can I compare two workbooks if they have different numbers of rows?

Yes. Using XLOOKUP or VLOOKUP is the best approach here because these functions search for a specific ID regardless of where it is located in the list. Visual comparison will not work if the row counts differ.

Is there a built-in "Compare Files" button in Excel?

Standard Excel does not have a single-click comparison button. However, professional versions of Office (like Office Professional Plus) include a separate standalone tool called Spreadsheet Compare, which can be found in the Windows Start menu under Microsoft Office tools.

How do I compare two workbooks for exact duplicates?

The fastest way is to copy the data from both workbooks into a single sheet, one under the other. Then, select the data and go to Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values.

Will these methods work on Excel for the Web?

Most of these methods, including XLOOKUP and Conditional Formatting, work in the web version. However, the "View Side by Side" feature is only available in the desktop application.

What is the difference between VLOOKUP and XLOOKUP for comparing data?

XLOOKUP is more flexible; it can look for data to the left of the identifier column and does not require you to count column index numbers. VLOOKUP only looks to the right and is more prone to breaking if you insert new columns into your dataset.