To compare two text strings, use =A1=B1, which returns TRUE if they match and FALSE if they don’t. This ignores case, so “Excel” and “EXCEL” both come back TRUE.
For a case-sensitive comparison, use =EXACT(A1,B1) instead — that returns FALSE for the same pair. To get a readable result rather than TRUE/FALSE, wrap either one in IF: =IF(EXACT(A1,B1),"Match","No Match").
One thing that catches people out: if two cells look identical but return FALSE, it’s almost always an invisible trailing space. Compare with =TRIM(A1)=TRIM(B1) to rule that out, or =EXACT(TRIM(CLEAN(A1)),TRIM(CLEAN(B1))) if the data came from a web page or PDF.
In Excel, you can compare two strings with each other using two methods:
- Case Sensitive
- Non-Case Sensitive
In this tutorial, we will learn to write a formula for both methods.
Compare Two Strings with Non-Case Sensitive Match
- First, enter the (=) sign in a cell.
- Refer to the cell with the first value.
- Again, enter (=).
- Refer to the cell with the second value.
- In the end, hit Enter to get the result.

You can see in the above example that in the first cell, you have “Excel”, and in the second cell, you have “EXCEL”. Both values are the same; the only difference is the case. As a result, we have TRUE. As I said, this formula will not consider the case of the text while comparing.
=text1 = text2
With the values in cells A1 and B1, the formula is:
=A1=B1
Compare Two Strings with Case Sensitive Match
A case-sensitive formula for comparing text strings considers whether the letters are uppercase or lowercase.
For example, “EXCEL” and “Excel” would be considered different strings because “EXCEL” has uppercase letters where “Excel” has lowercase ones. And, if you want to consider the text’s case while matching, you can use the EXACT function. EXACT function checks if two text strings are exactly the same, including uppercase and lowercase letters.
- Enter the EXACT function in a cell.
- Refer to the cell with the first value.
- Type a comma.
- Refer to the cell with the second value.
- Close the function and hit Enter to get the result.

The above formula checks if the text in cell A1 is the same as in cell B1, including the case of each letter. If they are the same, it returns TRUE; if not, it returns FALSE.
=EXACT(A1,B1)
Using IF to Compare Two Texts
You can also combine IF with both methods we have discussed above.

=IF(A1=B1,"Yes","No") =IF(EXACT(A2,B2),"Yes","No")
The first formula compares without the case, and the second one with the case. Both return “Yes” when the texts match and “No” when they don’t; you can change these two values to anything you want.
Ignore Extra Spaces while Comparing
Both methods treat a space as a character, so “Excel ” (with a space at the end) and “Excel” are not equal. If your data comes from another system, wrap both cells in TRIM, which removes the extra spaces before comparing:
=TRIM(A1)=TRIM(B1)
In the same way, a number stored as text (“123”) isn’t equal to the number 123. Convert one of them with TEXT or VALUE so both are the same type.
Check If One String Contains Another
Sometimes you don’t need a full match, only to know if one text is part of the other. Use SEARCH for a match that ignores the case and FIND for a case-sensitive match. Both return a position, so ISNUMBER turns the result into TRUE or FALSE:
=ISNUMBER(SEARCH(B1,A1))
=ISNUMBER(FIND(B1,A1))
Compare More Than Two Strings
To check if three or more cells have the same text (with the case), compare each cell with the first one using EXACT and count the matches. The following formula returns TRUE only when A1, B1 and C1 are all exactly the same:
=SUMPRODUCT(--EXACT(A1,A1:C1))=3
Frequently Asked Questions
Why does my comparison return FALSE when the texts look the same?
There’s usually an extra space or a hidden character in one of the cells, or one is a number and the other is text. Check the length of both cells with LEN; if the lengths differ, use TRIM (and CLEAN for hidden characters).
Can I check which text comes first alphabetically?
Yes. Use the less than operator (formula below), which returns TRUE when A1 comes first in alphabetical order. Like the = operator, it ignores the case.
=A1<B1
How do I highlight cells that don’t match?
Select the cells in column A, go to Home ➜ Conditional Formatting ➜ New Rule ➜ Use a formula to determine which cells to format, enter the following formula, and choose a fill color:
=NOT(EXACT(A1,B1))
A quick way to test the case-sensitive example is to keep two pairs: abc/ABC and abc/abc followed by a space. EXACT should reject both original pairs. Lowercasing fixes only the first; trimming fixes only the second. Keeping those tests separate helps when case is significant for a product code but an accidental trailing space is not.