Compare Two Cells in Excel (Exact, Ignoring Case or Spaces)
By ExcelReady TeamUpdated 6 min read
The short answer
To compare two cells in Excel, type =A2=B2. It returns TRUE if they match and FALSE if they don't, and it ignores capital letters. Use =EXACT(A2,B2) when case matters, =TRIM(A2)=TRIM(B2) to ignore extra spaces, and wrap any of these in IF to show words like "Match" or "Different" instead of TRUE or FALSE.
Key takeaways
- =A2=B2 returns TRUE or FALSE and treats "london" and "London" as the same.
- EXACT(A2,B2) is the case-sensitive version.
- Wrap each side in TRIM to ignore extra spaces at the start, end or middle.
- The number 100 and the text "100" are not equal; convert the text with VALUE first.
- Use IF to turn TRUE and FALSE into clear labels like Match and Different.
On this page+
- The sample data
- How to compare two cells with the equals sign
- Is the comparison case-sensitive? Use EXACT
- How to compare two cells ignoring extra spaces
- Show "Match" or "Different" instead of TRUE and FALSE
- Why two cells look the same but don't match
- How to compare numbers and dates
- Highlight differences between two cells
- Practise it
To compare two cells in Excel, type =A2=B2: Excel returns TRUE when they match and FALSE when they don't. That simple check ignores capital letters but not spaces, so you sometimes need EXACT for case or TRIM for stray spaces. This guide shows each type of comparison on one small table of names and numbers, for anyone checking data from two systems or answering a job-test question.
The sample data#
The examples compare a name list from a CRM with the same names from payroll. Each row has a different problem:
| A | B | |
|---|---|---|
| 1 | CRM name | Payroll name |
| 2 | ··Priya··Shah | Priya Shah· |
| 3 | Tom Becker | Tom Baker |
| 4 | Lina Ortiz | lina ortiz |
| 5 | Sam Lee | Sam Lee |
The dots (·) stand for extra spaces you can't normally see. Row 2 has two spaces before Priya, two between the names, and one after Shah in column B.
How to compare two cells with the equals sign#
The fastest way to compare two cells is a formula with one equals sign at the start and another between the cells. In C5, type:
=A5=B5The result is TRUE, because both cells say Sam Lee. The first = starts the formula; the second asks "is A5 equal to B5?". For Tom Becker and Tom Baker in row 3, the result is FALSE.
To test the opposite, use <>, which means "not equal to": =A3<>B3 returns TRUE because the names differ. Fill the formula down a whole column (Windows: Ctrl+D; Mac: ⌘D) to check every row at once. The TRUE, FALSE and comparisons lesson practises all six comparison operators.
Is the comparison case-sensitive? Use EXACT#
No. The equals sign ignores capital letters, so =A4=B4 returns TRUE for Lina Ortiz and lina ortiz. That is usually what you want with names and codes.
When case matters, for example with passwords, product codes like "AB-1x" or IDs from a system that treats "a" and "A" differently, use EXACT:
=EXACT(A4,B4)The result is FALSE, because the capitals differ. EXACT returns TRUE only when every character matches, including case. It ignores formatting, so bold text and plain text with the same letters still match.
How to compare two cells ignoring extra spaces#
Extra spaces are the most common reason two cells that look the same don't match. Row 2 returns FALSE with =A2=B2, even though both cells say Priya Shah. TRIM removes spaces at the start and end and turns runs of spaces in the middle into one space. Wrap each cell in TRIM:
=TRIM(A2)=TRIM(B2)The result is TRUE. The TRIM function guide explains exactly which spaces it removes. To ignore all spaces, even single ones between words, use SUBSTITUTE to delete them: =SUBSTITUTE(A2," ","")=SUBSTITUTE(B2," ",""). That makes "PriyaShah" equal to "Priya Shah", so use it for codes, not names. The guide to removing spaces in Excel covers both approaches.
You can combine fixes. =TRIM(A2)=TRIM(B2) already ignores case as well as spaces, because = ignores case. For a check that ignores spaces but does care about case, put TRIM inside EXACT:
=EXACT(TRIM(A2),TRIM(B2))Show "Match" or "Different" instead of TRUE and FALSE#
TRUE and FALSE are fine for you, but a report reads better with words. Wrap the comparison in IF, which returns one value when the test is TRUE and another when it is FALSE:
=IF(TRIM(A2)=TRIM(B2),"Match","Different")Row 2 returns Match and row 3 returns Different. To show only problems, leave the first answer empty: =IF(A2=B2,"","Check"). Then the column is blank except where something needs attention.
Why two cells look the same but don't match#
If =A2=B2 returns FALSE and you can't see why, the cells hold different characters. Check the length of each one with LEN:
=LEN(A2)"Priya Shah" has 10 characters, but in row 2 =LEN(A2) returns 13 and =LEN(B2) returns 11. The extra characters are the hidden spaces. The usual causes of a mismatch are:
| Cause | How to spot it | Fix |
|---|---|---|
| Extra spaces | LEN is higher than the visible text | TRIM |
| Line breaks or other hidden characters from a download | LEN is higher, and TRIM doesn't fix it | CLEAN, or SUBSTITUTE with CHAR(10) |
| Non-breaking spaces from web pages | TRIM leaves them | SUBSTITUTE(A2,CHAR(160)," ") |
| Number stored as text | The text sits on the left and may show a green triangle | VALUE |
Line breaks have their own guide: how to remove line breaks. For a full cleanup routine across a whole column, see how to clean messy data.
How to compare numbers and dates#
Numbers and dates compare the same way, with =A2=B2, but two traps catch people.
Numbers stored as text. The number 100 and the text "100" are not equal, so =A2=B2 returns FALSE. Convert the text side with VALUE: =VALUE(A2)=B2 returns TRUE.
Hidden decimals. Two cells can both show 10.25 while one really holds 10.2499 from a calculation, because number formatting hides the extra decimals. Compare after rounding, =ROUND(A2,2)=ROUND(B2,2), or allow a small tolerance with ABS: =ABS(A2-B2)<=0.01 returns TRUE when the numbers are within one cent.
Dates are numbers underneath, so two dates match when they are the same day, even if they are formatted differently. A date that came in as text, like "2026-03-05" sitting on the left of the cell, won't match a real date until you convert it with DATEVALUE.
Highlight differences between two cells#
To see differences at a glance instead of in a formula column, use conditional formatting with a formula rule:
- Select A2:B5.
- Go to Home > Conditional Formatting > New Rule.
- Choose Use a formula to determine which cells to format.
- Enter
=TRIM($A2)<>TRIM($B2)and pick a fill colour.
Every row where the names differ is highlighted, here just row 3. The $ before A and B keeps the rule looking at those two columns for every cell. To compare whole columns, not just pairs of cells, read how to compare two lists.
Practise it#
Try the exercise on this page: it compares two names that differ only by spaces. Then practise TRUE, FALSE and comparisons in a live spreadsheet, where you type each check and it is marked instantly, and use the cleaning messy text lesson to fix the spaces and capitals that make cells fail to match.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
Do the names in A2 and B2 match once extra spaces are removed? Click C2 and use IF with TRIM on both cells to return Match or Different.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Check | |||
| 2 | Priya Shah | |||
| 3 | Tom Baker | |||
| 4 | lina ortiz | |||
| 5 | Sam Lee | |||
| 6 | ||||
| 7 | ||||
| 8 |
Tip: Compare TRIM(A2) with TRIM(B2) inside IF, then give the word for TRUE first and the word for FALSE second.
Practise this in a lesson
Frequently asked questions
How do I check if two cells are the same in Excel?
Type =A2=B2 in an empty cell. Excel returns TRUE if the two cells hold the same value and FALSE if they don't. Capital letters are ignored.
How do I compare two cells for an exact match, including case?
Use =EXACT(A2,B2). It returns TRUE only when the text is identical, including capital letters. Formatting such as bold or colour is ignored.
Why does Excel say two cells are different when they look the same?
Usually one cell has an extra space, a hidden character, or a number stored as text. Compare =LEN(A2) and =LEN(B2) to find extra characters, and use TRIM, CLEAN or VALUE to fix them.
How do I compare two cells and return Yes or No?
Wrap the comparison in IF: =IF(A2=B2,"Yes","No"). You can use any words, or leave the second answer empty with "" to show only matches.
How do I compare two cells and highlight the differences?
Select the rows, go to Home > Conditional Formatting > New Rule, choose Use a formula, and enter =$A2<>$B2. Pick a fill colour and every row where the cells differ is highlighted.