Excel / Compare Two Text Values with EXACT

Use EXACT when two text values must match in both case and spacing. It returns TRUE if they match and FALSE if a character differs. Formatting such as font or cell color does not affect the result.

Compare two cells with EXACT

Enter the first text value or cell reference, then the second. The formula below compares the text in A2 and B2. Put a text value in double quotes when typing it directly into a formula.

=EXACT(A2,B2)

Microsoft’s EXACT function reference

Test differences in case and spacing

Enter the first two columns starting at A2 and B2. Put the formula in C2 and fill down. The quotes in the table show where each value starts and ends. Leave them out when typing into the cells, and keep the spaces shown. Enter a regular space for each ␠ marker.

EXACT results for sample text pairs
First text Second text Result
"AX-07" "AX-07" TRUE
"AX-07" "ax-07" FALSE
"AX-07" "AX-07␠" FALSE
"A␠␠B" "A␠B" FALSE

Only the first row returns TRUE. The second row differs in case, the third has a trailing space, and the fourth has a different number of spaces between letters. If a result surprises you, inspect the cell values in the formula bar.

Compare after cleaning unwanted spaces

If your comparison rules allow you to ignore ordinary extra spaces in imported data, run both values through TRIM first. The third example row then returns TRUE.

=EXACT(TRIM(A2),TRIM(B2))

TRIM also reduces repeated ordinary spaces inside a value to one, so the fourth row becomes TRUE too. TRIM alone does not remove nonbreaking spaces copied from web pages. If spacing matters in your identifiers, compare the original values.

Microsoft’s TRIM function reference

Label each row for review

Combine IF with EXACT in C2 to replace TRUE and FALSE with text. Fill down and inspect the rows marked “Review.”

=IF(EXACT(A2,B2),"Match","Review")

For example, formatting the number 7 as 000 displays 007 while leaving the stored value as 7. Store identifiers as text from the start when leading zeros matter. Use a numeric comparison when comparing the values of two numbers.