Different in Excel Formula: How to Compare Two Cells
In this article
To find if two cells are different in Excel, use the "not equal to" operator, which is written as <>. For example, the formula =A2<>B2 will return TRUE if the values are different and FALSE if they are identical. This is the fastest way to perform a logical comparison between two data points.
Comparing data is essential for auditing spreadsheets, finding discrepancies in pricing, or identifying changes between two versions of a list. Depending on your goal, you can use a simple logical test or wrap that test inside an IF statement to produce custom text like "Different" or "Match."
What You'll Need
- Microsoft Excel (any version)
- Two or more columns of data to compare
Step-by-Step
Method 1: Basic Logical Comparison (TRUE/FALSE)
- Open your Excel workbook and locate the two cells you wish to compare (e.g., Cell A2 and Cell B2).
- Click on an empty cell where you want the result to appear (e.g., Cell C2).
- Type the following formula:
=A2<>B2 - Press Enter.
- If the values in A2 and B2 are different, the cell will display TRUE. If they are the same, it will display FALSE.
- Hover your mouse over the bottom-right corner of cell C2 until the cursor turns into a small black cross (the fill handle), then click and drag downward to apply the formula to the rest of your list.
Method 2: Custom Labels using the IF Function
- Select the cell where you want your custom result (e.g., Cell C2).
- Type the following formula:
=IF(A2<>B2, "Different", "Match") - Press Enter.
- Excel will now display the word "Different" whenever the cells do not match and "Match" whenever they do.
- Drag the fill handle down to apply this to all rows in your dataset.
Method 3: Case-Sensitive Comparison
- If you need to differentiate between "Apple" and "apple", the standard
<>operator will not work because it is not case-sensitive. - In cell C2, type:
=NOT(EXACT(A2, B2)) - Press Enter.
- The
EXACTfunction checks if two strings are identical, including capitalization. By wrapping it inNOT, you tell Excel to return TRUE only when the cells are different.
Common Mistakes
- Using the wrong symbol: Many users try to use
!=(which is common in other programming languages). Excel does not recognize!=; you must use<>. - Ignoring hidden spaces: A cell containing "Blue" and a cell containing "Blue " (with a trailing space) will be marked as "Different." These spaces are invisible but counted as characters.
- Comparing different data types: Comparing a number stored as text (e.g., '100) to a number stored as a value (100) will result in a "Different" outcome, even though they look the same.
- Forgetting the equals sign: Every formula must start with
=. If you typeA2<>B2without the equals sign, Excel treats it as plain text.
Tips
- Use Conditional Formatting: Instead of a formula in a new column, select your data and go to Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values. Change the dropdown from "Duplicate" to "Unique" to instantly highlight all different values in a range.
- Clean your data first: Use the
=TRIM()function on your data before comparing it. This removes leading and trailing spaces that often cause false "Different" results. - Absolute References: If you are comparing a whole column against one single cell (e.g., comparing everything in column A to cell G1), use an absolute reference:
=A2<>$G$1. The dollar signs lock the reference so it doesn't shift when you drag the formula down.
Troubleshooting
The formula returns #NAME?
This usually happens if you misspelled a function name (e.g., typing =IFN(...) instead of =IF(...)) or if you forgot to put quotation marks around your custom text labels. Ensure your text is inside double quotes: "Different".
The formula says they are different, but they look identical
This is almost always caused by invisible characters or formatting differences. To test this, use the =LEN() function on both cells (e.g., =LEN(A2) and =LEN(B2)). If one cell has a length of 5 and the other has 6, there is a hidden space or character causing the discrepancy.
The formula returns #VALUE!
This can occur if you are comparing a cell containing an error (like #DIV/0!) to a normal cell. You can wrap your formula in =IFERROR(your_formula, "Error in Data") to handle these cases cleanly.
Frequently Asked Questions
Can I find differences between two entire sheets?
Yes. You can create a third "comparison" sheet. In cell A1 of the third sheet, enter =Sheet1!A1<>Sheet2!A1 and drag that formula across and down to cover the dimensions of your data. Any cell showing TRUE is a difference.
Is there a way to highlight differences without a formula?
Yes, use the "Go To Special" feature. Select your data range, press Ctrl + G, click Special, select Row differences, and click OK. Excel will select all cells in the rows that differ from the first column.
Does the "not equal to" operator work for dates?
Yes. Excel stores dates as serial numbers, so <> works perfectly for dates. If two dates are different, it will return TRUE.
Can I compare more than two cells at once?
The <> operator only compares two items. To check if three or more cells are different, you can use the COUNTUNIQUE function (in Google Sheets) or a combination of SUMPRODUCT and COUNTIF in Excel to see if the number of unique values is greater than one.
How do I make the "Different" result a specific color?
Use Conditional Formatting. Select the cells containing your formulas, go to Home > Conditional Formatting > Highlight Cells Rules > Text that Contains..., type "Different", and choose a red fill.