To check if two cells match in Excel, type =A2=B2 in a third cell: it returns TRUE when the values are equal and FALSE when they are not. For a readable result, wrap it in IF: =IF(A2=B2,"Match","No match").
The examples assume the values to compare are in columns A and B, starting in row 2, and the result goes in column C. Type the formula in C2, then drag the fill handle down to copy it to the other rows. The cell references are relative, so row 3 compares A3 with B3, and so on.
Which formula should you use?
| Goal | Formula | Case sensitive |
|---|---|---|
| TRUE or FALSE | =A2=B2 | No |
| Yes/No style label | =IF(A2=B2,"Match","No match") | No |
| Exact match including capitals | =EXACT(A2,B2) | Yes |
| Flag the differences | =A2<>B2 | No |
| Ignore stray spaces | =TRIM(A2)=TRIM(B2) | No |
Compare two cells with the equal sign
=A2=B2
The first = starts the formula. The second is the comparison operator, which Microsoft lists as "Equal to" with the example =A1=B1. Every comparison operator returns TRUE or FALSE. The same table lists <> as "Not equal to", which is what you use to find differences instead of matches.
The comparison works on numbers, text, dates and TRUE/FALSE values. Example output for three rows:
| A | B | C (=A2=B2) |
|---|---|---|
| apple | apple | TRUE |
| apple | pear | FALSE |
| Apple | apple | TRUE |
The third row shows the catch: this comparison ignores capital letters, so "Apple" equals "apple". You can confirm it on your own sheet by typing both words into two cells. If capitals matter, use EXACT, covered below.
Show Match or No match with IF
=IF(A2=B2,"Match","No match")
Microsoft gives the syntax as IF(logical_test, value_if_true, [value_if_false]). Here the logical test is A2=B2. The second argument is what you see when it is TRUE, and the third is what you see when it is FALSE. Text inside a formula must be wrapped in straight double quotes, as Microsoft's IF page points out. Numbers and the words TRUE and FALSE do not need them.
You can put anything in those arguments. To mark only the problems and leave matching rows empty, use an empty string for the TRUE result:
=IF(A2=B2,"","Check this row")
This is handy for long lists, because the rows that need attention are the only ones with text in column C.
Check if two cells match exactly, including case
=EXACT(A2,B2)
Microsoft describes EXACT(text1, text2) as comparing two text strings and returning TRUE "if they are exactly the same, FALSE otherwise." It is case-sensitive, but it ignores formatting differences such as bold or font colour. Microsoft's own examples show that "Word" against "word" is FALSE, and that "w ord" against "word" is FALSE because of the space.
With the same three rows as above, =EXACT(A4,B4) returns FALSE for "Apple" and "apple". Use it for case-sensitive data such as product codes, passwords in a test sheet, or file names on a case-sensitive system.
To get a label, nest it in IF:
=IF(EXACT(A2,B2),"Match","No match")
EXACT already returns TRUE or FALSE, so you do not need to add =TRUE after it.
Find the cells that do not match
=A2<>B2
This returns TRUE when the cells differ. Combine it with a filter on column C to show only the mismatches. If you prefer the label version, =IF(A2<>B2,"Different","") gives the same result as the "Check this row" formula above.
Why two cells that look the same do not match
When =A2=B2 returns FALSE for values that look identical, the cause is almost always hidden content in one of the cells.
- Extra spaces. "apple " with a trailing space is not "apple". Run
=LEN(A2)and=LEN(B2). If the lengths differ, there is hidden text. Compare the trimmed values instead:=TRIM(A2)=TRIM(B2). Microsoft says TRIM removes all spaces from text except single spaces between words. - Nonbreaking spaces. Text copied from web pages often contains the Unicode nonbreaking space, decimal value 160. Microsoft states that TRIM by itself does not remove it, because it was designed for the 7-bit ASCII space (value 32). If
LENstill shows an extra character after TRIM, replace character 160 first:=TRIM(SUBSTITUTE(A2,CHAR(160)," ")). - Numbers stored as text. A cell can display 42 and still hold the text "42". Test with
=ISNUMBER(A2)and=ISNUMBER(B2). If one is TRUE and the other FALSE, convert the text cell to a number before comparing. - Different decimals. A cell showing 0.3 may hold a longer value, because the display format only rounds what you see. Widen the decimals, or compare rounded values with
=ROUND(A2,2)=ROUND(B2,2).
Compare two columns of data
Fill the formula down the full length of both columns. To count how many rows match, you can add up the TRUE results from a column of =A2=B2 formulas using =COUNTIF(C2:C100,TRUE). This compares row against row, so A2 is only ever checked against B2.
If you instead want to know whether a value from one column appears anywhere in another list, in any row, that is a lookup problem rather than a same-row comparison. See Excel check if value is in list for the COUNTIF, MATCH and XLOOKUP formulas.
Compare cells on different sheets
Put the sheet name and an exclamation mark before the cell reference:
=Sheet1!A2=Sheet2!A2
If a sheet name contains spaces, wrap it in single quotes, for example ='Price List'!A2=A2. The comparison behaves exactly as it does on a single sheet, including the case-insensitivity and the hidden-character problems above.
Frequently asked questions
- What is the formula to check if two cells match in Excel?
- Type =A2=B2 in a third cell. Excel returns TRUE when the two cells hold the same value and FALSE when they differ. To show words instead, use =IF(A2=B2,"Match","No match"). Replace A2 and B2 with the cells you want to compare.
- Is the = comparison case sensitive in Excel?
- No. A formula such as =A2=B2 treats "Word" and "word" as equal. For a case-sensitive comparison use =EXACT(A2,B2), which Microsoft documents as case-sensitive but ignoring formatting differences.
- How do I find cells that do not match?
- Use the not-equal operator: =A2<>B2 returns TRUE when the cells differ. In an IF formula, =IF(A2<>B2,"Different","") shows a label only for mismatches and leaves the other rows blank.
- Why does Excel say two identical-looking cells do not match?
- The usual causes are extra spaces, a nonbreaking space (character 160) that TRIM does not remove, or a number stored as text in one cell and a real number in the other. Check each cell with =LEN(A2) and =ISNUMBER(A2) to see which applies.