Text cleanup
How to Remove Special Characters and Line Breaks in Excel
For line breaks and non-printing characters use =CLEAN(A2). For one known character use =SUBSTITUTE(A2,"#",""). For characters you cannot type, find the code with =UNICODE(MID(A2,n,1)) and remove it with =SUBSTITUTE(A2,UNICHAR(code),""). For line breaks in many cells at once, press Ctrl+H, click in "Find what", press Ctrl+J, leave "Replace with" empty and choose Replace All.
Text pasted from websites, PDFs, emails and other systems carries characters that look harmless and break lookups, imports and sorting. A cell that seems to contain "ABC" may really hold a zero-width space in front of it, which is why =A2="ABC" says FALSE. The fix is to find out which character it is and remove exactly that.
Step 1: find out what is really in the cell
Compare what you see with what is there:
=LEN(A2)
If a cell showing "ABC" has a length of 4, something invisible is in it. To read the code of the first character, or the nth:
=UNICODE(MID(A2,1,1))
Change the 1 to look at each position. Ordinary letters and digits are below 128.
Step 2: the common culprits
| Character | Code | Typical source | Remove with |
|---|---|---|---|
| Line break | 10 | Text with Alt+Enter, web forms | =SUBSTITUTE(A2,CHAR(10)," ") |
| Carriage return | 13 | Windows files | =SUBSTITUTE(A2,CHAR(13),"") |
| Tab | 9 | Text pasted from tables | =SUBSTITUTE(A2,CHAR(9)," ") |
| Non-breaking space | 160 | Web pages | =SUBSTITUTE(A2,UNICHAR(160)," ") |
| Zero-width space | 8203 | Web pages, chat apps | =SUBSTITUTE(A2,UNICHAR(8203),"") |
| Byte order mark | 65279 | Start of some CSV files | =SUBSTITUTE(A2,UNICHAR(65279),"") |
| Curly single quote | 8216, 8217 | Word, email | =SUBSTITUTE(SUBSTITUTE(A2,UNICHAR(8216),"'"),UNICHAR(8217),"'") |
| Curly double quote | 8220, 8221 | Word, email | =SUBSTITUTE(SUBSTITUTE(A2,UNICHAR(8220),""""),UNICHAR(8221),"""") |
| En and em dash | 8211, 8212 | Word, web | =SUBSTITUTE(SUBSTITUTE(A2,UNICHAR(8211),"-"),UNICHAR(8212),"-") |
A byte order mark at the start of a CSV file usually shows as  in the first header, and it can stop the first column from being recognised.
Step 3: CLEAN for non-printing characters
=CLEAN(A2)
CLEAN removes the first 32 non-printing characters, such as line breaks. It does not remove the non-breaking space or the zero-width space, so combine them:
=TRIM(CLEAN(SUBSTITUTE(SUBSTITUTE(A2,UNICHAR(160)," "),UNICHAR(8203),"")))
Step 4: Find and Replace for the whole sheet
Press Ctrl+H. To remove line breaks, click in "Find what" and press Ctrl+J (nothing visible appears, which is normal), type a space or nothing in "Replace with", and choose Replace All. To remove a literal asterisk or question mark, type ~* or ~?, because the tilde tells Excel the next character is not a wildcard.
Step 5: keep only letters, digits and spaces (Microsoft 365)
If you want to strip everything else, for example from a reference code:
=LET(t,A2,c,MID(t,SEQUENCE(LEN(t)),1),CONCAT(IF(ISNUMBER(FIND(c,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ")),c,"")))
This removes accented letters too, so do not use it on names. It needs a version of Excel with LET, SEQUENCE and CONCAT (Microsoft 365 or 2021).
Warning: removing special characters from names, addresses or other text in another language destroys information. Remove only the characters you have identified.
Paste the result as values
Formulas live in a helper column. When the result looks right, copy it and use Paste Special, Values over the original, then delete the helper column.
A whole file at once
DecodingPro cleans stray whitespace and invisible characters in text cells and repairs garbled characters where the cause is clear, and it lists each change so nothing is altered silently.
You start with 100 free credits. Every change is logged, and anything unclear is flagged, never guessed.
Fix a spreadsheetQuestions people ask
Why does TRIM not remove the space in my cell?
It is probably a non-breaking space (code 160). Replace it first: =TRIM(SUBSTITUTE(A2,UNICHAR(160)," ")).
How do I remove a line break from a cell?
Use =SUBSTITUTE(A2,CHAR(10)," "), or select the cells and use Ctrl+H with Ctrl+J in "Find what".
What is the difference between CHAR and UNICHAR?
CHAR covers only codes 1 to 255. UNICHAR covers all Unicode characters, so it is the one to use for curly quotes, dashes and zero-width characters.