Why is my IF formula not matching text that looks the same?
Formula (Excel and Google Sheets)
=IF(TRIM(B2)="Paid","Closed","Chase")The cell has hidden spaces, so "Paid " isn't "Paid". Trim it in the test: =IF(TRIM(B2)="Paid","Closed","Chase").
- Result on the example
- one result per row in
C2, filled down toC7 - Works in
- Every current version
- Google Sheets
- Same formula
See it work
The formula is already in C2, filled down to C7. Change any input and the result updates, or edit the formula to experiment.
How it works
Imported text often carries spaces you can't see: "Paid " is not equal to "Paid", so the IF goes the wrong way. TRIM removes spaces at both ends (and doubled spaces inside) before the comparison. Case isn't the problem: "PAID" already matches, because = ignores case.
=IF(TRIM(B2)="Paid","Closed","Chase")Result"Closed"
B2"Paid"The value in B2.
TRIM(B2)"Paid"TRIM: Removes extra spaces, leaving single spaces between words.- text
B2"Paid"
- text
TRIM(B2)="Paid"TRUEThe = operator tests whether the two sides are equal.
IF(TRIM(B2)="Paid","Closed","Chase")"Closed"IF: Returns one value if a test is true, another if false.- logical_test
TRIM(B2)="Paid"TRUE - value_if_true
"Closed" - value_if_false
"Chase"not used
- logical_test
In Google Sheets
The same formula works in Google Sheets: =IF(TRIM(B2)="Paid","Closed","Chase"). We ran it in Google Sheets mode on the same data and it returns the same results.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =IF(B2="Paid","Closed","Chase") | Closed, Chase, Chase…Different result | The plain comparison. "Paid " and " Paid" show Chase. |
| =IF(TRIM(CLEAN(B2))="Paid","Closed","Chase") | Closed, Closed, Chase… | CLEAN also strips line breaks and other non-printing characters that come with pasted data. |
Common mistakes
- Non-breaking spaces from web pages survive TRIM. Replace them first:
SUBSTITUTE(B2,CHAR(160)," "). - Check a suspicious cell with
=LEN(B2): "Paid " has 5 characters.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Why is my IF formula not matching text that looks the same
C2, show "Closed" when the status is Paid, even with stray spaces around it, otherwise "Chase". Fill down to C7.Questions
How do I clean the whole column?
Helper column =TRIM(B2), then Paste Values over the original.
How do I make the comparison case-sensitive?
=IF(EXACT(TRIM(B2),"Paid"),"Closed","Chase").
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.