Difference Excel Function: How to Compare Two Columns
In this article
The DIFFERENCE function doesn't exist in Excel, but you can compare two columns using subtraction, EXACT, or IF formulas to find discrepancies. This lets you spot mismatches between datasets — useful for reconciling invoices, validating data imports, or auditing records. No add-ins or special tools are needed; all methods use built-in Excel functions.
What You'll Need
- Microsoft Excel (2010 or later, on Windows or Mac)
- Two columns of data to compare (e.g., Column A and Column B)
- At least one empty column to display results
Step-by-Step
- Open your Excel file and ensure both columns you want to compare are clean and formatted consistently — for example, both as text or both as numbers. Remove extra spaces by selecting each column, pressing Ctrl+H, typing a single space in "Find what", leaving "Replace with" blank, then clicking "Replace All".
- Click on the first empty cell in a new column next to your data (e.g., if comparing A2:A100 and B2:B100, click C2).
- Enter the formula
=A2=B2and press Enter. This returns TRUE if the values match exactly, FALSE if they don’t. This works for numbers, dates, and text, but is case-insensitive for text. - Drag the fill handle (small square at the bottom-right corner of the selected cell) down to apply the formula to all rows in your dataset. Alternatively, double-click the fill handle to auto-fill to the last row with data.
- To highlight mismatches visually, select the entire results column (C2:C100), go to Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format, enter
=C2=FALSE, click Format, choose a red fill, then click OK. - For case-sensitive comparison of text, use
=EXACT(A2,B2)instead of=A2=B2. This returns TRUE only if the text matches exactly, including uppercase and lowercase letters. - To return custom messages like "Match" or "Mismatch", wrap the formula in an IF statement:
=IF(A2=B2,"Match","Mismatch"). This makes results easier to read for non-technical users. - If comparing numeric values and you want to know the exact difference (not just match/fail), use
=A2-B2. A result of 0 means no difference; positive or negative numbers show the gap. - For large datasets, filter the results column to show only FALSE or "Mismatch" entries. Click the filter button in the column header, uncheck TRUE or "Match", then click OK to view only discrepancies.
Common Mistakes
- Comparing text with leading or trailing spaces — Excel treats "Apple " and "Apple" as different. Always clean data first using TRIM() or Find & Replace.
- Using =A2=B2 on mixed data types — e.g., comparing a number (123) to text that looks like a number ("123"). Excel may return FALSE even if they appear identical. Convert both to the same type using VALUE() or TEXT().
- Forgetting to lock cell references when copying formulas across rows and columns — always use absolute references (e.g., $A$2) if referencing a fixed cell, or ensure relative references are intended.
- Assuming =A2=B2 detects formatting differences — it doesn’t. Two cells can look different (e.g., one bold) but still return TRUE if the underlying value matches.
- Using the wrong column reference — accidentally comparing A2 with C2 instead of B2. Always double-check the formula references after dragging.
Tips
- Use the IFERROR function when comparing values that might cause errors:
=IFERROR(A2=B2,"Error")to avoid #VALUE! or #N/A results. - For comparing entire ranges (not just row by row), use array formulas like
=SUMPRODUCT(--(A2:A100<>B2:B100))to count total mismatches without helper columns. - Copy and paste results as values after verification to prevent formula recalculation from hiding changes during edits.
- Use Data > Remove Duplicates on the combined columns if you want to find unique entries across both lists — this reveals records that appear in one column but not the other.
- Combine with VLOOKUP or XLOOKUP to pull related data from mismatched rows for deeper analysis.
- Save a backup copy before applying formulas to large datasets — especially if you plan to delete or restructure rows based on results.
Troubleshooting
- Formula shows as text instead of a result: Check if the cell is formatted as Text. Right-click the cell > Format Cells > Change to General or Number, then press F2 and Enter to re-evaluate.
- Results are all TRUE even when data differs: Verify that the data isn’t being pulled from a source that auto-updates or uses formulas. Check cell contents by selecting the cell and viewing the formula bar.
- Excel returns #NAME? error: You likely misspelled a function. Double-check spelling: EXACT, not Exact; IF, not If.
- Conditional formatting isn’t highlighting: Confirm the rule applies to the correct range (e.g., C2:C100, not C2:C10). Edit the rule and check the "Applies to" range.
- Formula works on one row but not others: Check for hidden characters. Use =LEN(A2) and =LEN(B2) to compare character counts — different lengths mean hidden spaces or line breaks.
- Workbook is slow with large comparisons: Switch from volatile functions like TODAY() or RAND() in other cells, or temporarily disable automatic calculation: Formulas > Calculation Options > Manual.
Frequently Asked Questions
Can I compare three columns at once in Excel?
Yes, use nested logic like=AND(A2=B2,B2=C2) to return TRUE only if all three match. For partial matches, use =OR(A2=B2,A2=C2,B2=C2) to detect any two that align.
Why does Excel say two identical numbers don’t match?
Due to floating-point precision. For example, 0.1+0.2 may display as 0.3 but store as 0.30000000000000004. Use ROUND() to truncate decimals:=ROUND(A2,2)=ROUND(B2,2).
How do I find values in Column A that aren’t in Column B?
Use=ISNA(MATCH(A2,B:B,0)). This returns TRUE if the value in A2 is not found anywhere in Column B. Filter for TRUE to see missing entries.
Can I compare sheets or workbooks using this method?
Yes, reference cells from another sheet:=Sheet2!A2=A2. For different workbooks, open both and use [Book2.xlsx]Sheet1!$A$2=A2. Ensure both files are open when entering the formula.