To compare two cells in Excel, use =A2=B2; it returns TRUE when their contents match and FALSE when they do not, without distinguishing uppercase from lowercase. For a case-sensitive comparison, use =EXACT(A2,B2). The right choice depends on whether you need a basic match, an exact character-for-character check, or a more flexible test such as finding text within a cell.
How the basic comparison works
Excel’s equals operator compares the values in two cells and returns a logical result: TRUE or FALSE. With text in A2 and B2, enter =A2=B2 in another cell. If A2 contains North and B2 contains north, the result is TRUE because the comparison is not case-sensitive. If B2 contains Northside, the result is FALSE.
The operator checks the complete cell values, not just whether one value appears somewhere inside the other. It also does not ignore ordinary spaces or punctuation. For example, “Blue sky” and “Blue sky ” (with a trailing space) are different, even though the extra space can be hard to see. This formula is usually the simplest option when comparing entries such as product names, labels, or responses and capitalization is not meaningful.
To show a word instead of TRUE or FALSE, wrap the comparison in IF. With the values to compare in A2 and B2, enter =IF(A2=B2,"Match","Different"). It displays Match if Excel considers the cells equal and Different otherwise. You can replace those result labels with any text that suits a report.
When to use EXACT for capitalization
Use EXACT when uppercase and lowercase letters must count as different. With the strings in A2 and B2, enter =EXACT(A2,B2). If A2 is “Report” and B2 is “report”, the result is FALSE. If both contain “Report” with the same capitalization and characters, it is TRUE.
EXACT is useful for checking case-sensitive codes, identifiers, or text that must match precisely. It compares the strings character by character, including spaces and punctuation. Like the equals operator, it returns a Boolean result, so you can use it directly in a formula or place it inside IF. With A2 and B2 holding the strings, enter =IF(EXACT(A2,B2),"Exact match","Not exact") to return a readable label.
There is no need to use EXACT for every text comparison. If capitalization is incidental—for example, a customer typed a name with a different case—A2=B2 is simpler and already ignores that difference. Choose based on what the data represents, not just on which formula looks more precise.
Compare text after cleaning extra spaces
A common reason two entries appear identical but compare as different is hidden or repeated spacing. TRIM removes leading and trailing ordinary spaces and reduces repeated spaces between words to a single space. With the text in A2 and B2, use =EXACT(TRIM(A2),TRIM(B2)) for a case-sensitive comparison after that cleanup. For example, “Red apple ” in A2 and “Red apple” in B2 return TRUE after TRIM removes the extra spaces.
If capitalization should not matter, compare the cleaned values with the equals operator instead. With the entries in A2 and B2, enter =TRIM(A2)=TRIM(B2). This still returns TRUE for capitalization differences, while disregarding the ordinary leading, trailing, and repeated spaces handled by TRIM.
TRIM does not remove every character that looks like a space. Data copied from a website or another system may contain a nonbreaking space, whose character code is 160. If that is the cause, replace those characters with ordinary spaces before trimming. With the original strings in A2 and B2, use =TRIM(SUBSTITUTE(A2,CHAR(160)," "))=TRIM(SUBSTITUTE(B2,CHAR(160)," ")). This comparison is case-insensitive; it replaces nonbreaking spaces, trims the result, and then compares the cleaned text. Check the source data before applying cleanup, since normalizing spaces may not be appropriate for every code or identifier.
Find a word or phrase inside a cell
A full-cell comparison is different from a search for part of a cell’s text. SEARCH finds a phrase within a longer string and is not case-sensitive. With a sentence in A2, enter =ISNUMBER(SEARCH("cat",A2)). If A2 contains “The cat is sleeping,” the result is TRUE; if it contains “The dog is sleeping,” it is FALSE. SEARCH returns a position when it finds the phrase and an error when it does not, so ISNUMBER turns that result into a convenient TRUE or FALSE.
For a case-sensitive partial search, use FIND in the same pattern. With text in A2, enter =ISNUMBER(FIND("Cat",A2)). It returns TRUE for “Cat nap” but FALSE for “cat nap.” SEARCH and FIND are for locating text within a cell; they do not replace the direct A2=B2 comparison when you need to know whether two complete cells match.
SEARCH treats the asterisk and question mark as wildcard characters. If you need to search for one of those characters literally, precede it with a tilde in the search text. This is a detail worth checking when searching filenames, product codes, or other values that can contain wildcard symbols.
Compare several pairs or use a result in another formula
For a row containing multiple fields, combine comparisons with AND when every pair must match. Suppose A2 and B2 contain the first pair, and C2 and D2 contain the second pair. Enter =AND(A2=B2,C2=D2). It returns TRUE only when both comparisons are TRUE. If either pair differs, the result is FALSE. This is useful for validating a record made up of several columns.
Use OR when a match in any one of several comparisons is enough. With A2 compared with B2 and C2, enter =OR(A2=B2,A2=C2). It returns TRUE if A2 matches either cell, and FALSE if it matches neither. These formulas can also feed IF, conditional formatting, or other calculations. When a row has many fields, keep the comparison logic easy to audit by labeling the columns clearly and testing a few known matches and mismatches.
A comparison can also be used as a filter condition in a larger formula, but the simplest check is often easier to troubleshoot in a spare column first. Once the result is correct for representative rows—including differences in case, spaces, and punctuation—you can build on it.
Common problems and how to diagnose them
- Numbers stored as text: A cell may display 123 while containing the text string “123”; a true numeric value and a text value are not always interchangeable in comparisons. Check how the source was imported and whether the cells are consistently stored as numbers or text.
- Invisible characters: Leading or trailing spaces, nonbreaking spaces, and control characters can make two apparently identical entries differ. Inspect the source or test a cleaned copy before changing the original data.
- Case expectations: The equals operator ignores capitalization, while EXACT distinguishes it. A FALSE from EXACT may therefore be correct rather than an error.
- Blank cells: Two blank cells compare as equal with the equals operator. A formula that returns an empty string can also look blank, even though it is not an empty cell in the same sense. If blanks should not count as a match, include a separate nonblank test in your logic.
- Errors in source cells: If a cell contains an error such as #N/A, a direct comparison can return an error instead of TRUE or FALSE. Fix or handle the error in the source data if the comparison must produce a clean status.
When a result surprises you, test one issue at a time: compare the original cells, inspect their contents in the formula bar, and then try an explicitly cleaned or case-sensitive comparison. Avoid cleaning source values blindly; for some identifiers, repeated spaces or capitalization may be meaningful.
Highlight differences with conditional formatting
A formula can identify differences visually as well as return a result in a cell. To highlight mismatches between two columns, select the range A2:B20, then choose Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format. With the values being compared in columns A and B, enter =$A2<>$B2 in the rule’s formula box, choose a format, and confirm the rule. The dollar signs keep the comparison columns fixed while the row number adjusts for each row. Both cells in a selected row will be highlighted when the two values differ. This rule uses the ordinary case-insensitive comparison, so it will not flag capitalization alone.
For case-sensitive highlighting, use EXACT in the rule instead. With the comparison range still beginning at row 2 and the values in A and B, use =NOT(EXACT($A2,$B2)). It highlights a row when the strings differ by case or another character. In Excel for Microsoft 365 on Windows, these rules are available through the Conditional Formatting menu. The same feature is available in Excel for Mac, although ribbon layout and dialog appearance can differ; Excel for the web also supports conditional formatting, with some interface differences.
Frequently Asked Questions
What is the simplest formula to compare two text cells in Excel?
Use =A2=B2 when the text is in A2 and B2. It returns TRUE for a match and FALSE otherwise, and it ignores differences in capitalization.
How do I compare text in Excel and make it case-sensitive?
Use =EXACT(A2,B2) when the strings are in A2 and B2. It returns TRUE only if the characters, including letter case, match.
Why does Excel say two identical-looking text values are different?
One value may contain a leading, trailing, repeated, or nonbreaking space, or another hidden character. Try comparing cleaned copies with TRIM, and check whether the data came from an external source.
How do I check whether a cell contains a word?
With the text in A2, use =ISNUMBER(SEARCH("word",A2)). SEARCH is case-insensitive and checks for the word inside the cell rather than comparing the entire cell value.
Can I compare two cells and display custom text?
Yes. With the values in A2 and B2, use =IF(A2=B2,"Match","Different"). Change the two quoted labels to the messages you want Excel to display.
Related
- Excel Custom Number Format: Show Numbers in Thousands
- Excel Shortcut to Select the Rest of a Column Down
- Excel Shortcut to Select an Entire Column
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Excel Filter Numbers From Text: Formulas and StepsTo filter Excel rows where a text cell contains one or more digits, add a helper column with…
- Weighted Average in Excel: Formula and ExamplesExcel has no dedicated WEIGHTEDAVERAGE function; use SUMPRODUCT divided by SUM. With values in B2:B4 and their corresponding…
- Excel Formula to Find Unique Names in a List With ExamplesIn Microsoft 365 or Excel 2021 and later, enter =UNIQUE(A2:A100) to return each distinct name from the list…
- Excel IFS in Multiple Cells: Apply Logic Across RangesTo use IFS in multiple cells, write the formula for the first row, then copy or fill it…
- Count Excel Rows After a Filter: Formulas That WorkTo count rows currently visible after filtering, use SUBTOTAL on a column that has a value in every…
- Excel SEQUENCE Function for Dates: Examples and TipsIn Excel for Microsoft 365, use =SEQUENCE(7,1,DATE(2026,4,1),1) to generate seven consecutive date values starting April 1, 2026. Format…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.