ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Text
  3. Compare Two Cells in Excel (Exact, Ignoring Case or Spaces)

Compare Two Cells in Excel (Exact, Ignoring Case or Spaces)

By ExcelReady Team·Updated November 2, 2026·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+
  1. The sample data
  2. How to compare two cells with the equals sign
  3. Is the comparison case-sensitive? Use EXACT
  4. How to compare two cells ignoring extra spaces
  5. Show "Match" or "Different" instead of TRUE and FALSE
  6. Why two cells look the same but don't match
  7. How to compare numbers and dates
  8. Highlight differences between two cells
  9. 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:

AB
1CRM namePayroll name
2··Priya··ShahPriya Shah·
3Tom BeckerTom Baker
4Lina Ortizlina ortiz
5Sam LeeSam 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:

Excel formula
=A5=B5

The 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:

Excel formula
=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:

Excel formula
=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:

Excel formula
=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:

Excel formula
=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:

Excel formula
=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:

CauseHow to spot itFix
Extra spacesLEN is higher than the visible textTRIM
Line breaks or other hidden characters from a downloadLEN is higher, and TRIM doesn't fix itCLEAN, or SUBSTITUTE with CHAR(10)
Non-breaking spaces from web pagesTRIM leaves themSUBSTITUTE(A2,CHAR(160)," ")
Number stored as textThe text sits on the left and may show a green triangleVALUE

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:

  1. Select A2:B5.
  2. Go to Home > Conditional Formatting > New Rule.
  3. Choose Use a formula to determine which cells to format.
  4. 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.

fx
ABCD
1
CRM name
Payroll name
Check
2
Priya Shah
Priya Shah
3
Tom Becker
Tom Baker
4
Lina Ortiz
lina ortiz
5
Sam Lee
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

LessonTRUE, FALSE and comparisonsAsk Excel yes-or-no questions with =, <>, >, <, >= and <=, and get TRUE or FALSE back. The building block of every IF.LessonCleaning messy textFix stray spaces, random capitals and inconsistent separators in imported data with TRIM, PROPER, UPPER, LOWER and SUBSTITUTE.Function guideTRIMClean imported data with Excel's TRIM: strip leading, trailing and double spaces so lookups and counts work. Examples and live practice.

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.

Sources

  • EXACT function - Microsoft Support
  • TRIM function - Microsoft Support
  • Calculation operators and precedence in Excel - Microsoft Support

Written and checked by the ExcelReady Team. First published November 2, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. The sample data
  2. How to compare two cells with the equals sign
  3. Is the comparison case-sensitive? Use EXACT
  4. How to compare two cells ignoring extra spaces
  5. Show "Match" or "Different" instead of TRUE and FALSE
  6. Why two cells look the same but don't match
  7. How to compare numbers and dates
  8. Highlight differences between two cells
  9. Practise it

Keep reading

Lookups· 5 min read

How to Compare Two Lists in Excel

To compare two lists in Excel, use COUNTIF to check whether each item in one list appears in the other: =IF(COUNTIF($C$2:$C$6,A2)>0,"Yes","No"). To list the missing items in one go, use FILTER with COUNTIF. To see the differences at a glance, add a conditional formatting rule that highlights items with no match.

Text· 7 min read

Clean Messy Data in Excel With TRIM, CLEAN and PROPER

Use TRIM to remove extra spaces, CLEAN to remove hidden non-printing characters, and PROPER to put a capital at the start of each word. Nest them to fix several problems at once: =PROPER(TRIM(A2)) turns " maria gonzalez" into "Maria Gonzalez". Build the clean version in a new column, check it, then paste it as values.

Text· 6 min read

How to Remove Spaces in Excel (Extra, Leading, All)

To remove extra spaces in Excel, use =TRIM(A2). It deletes spaces at the start and end and turns double spaces between words into single ones. To remove every space, use =SUBSTITUTE(A2," ",""). If spaces survive both, they are non-breaking spaces from the web: use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).

More on text

  • Concatenate With a Space, Comma or Dash in Excel
  • Count Characters and Words in a Cell in Excel
  • Create Email Addresses From Names in Excel
  • Case-Sensitive Matching in Excel With EXACT
  • Extract the Domain or Username From an Email in Excel
  • Extract the Domain From a URL in Excel
All text articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free