Text cleanup

How to Remove Special Characters and Line Breaks in Excel

By the DecodingPro teamUpdated 4 min read

Quick answer

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

CharacterCodeTypical sourceRemove with
Line break10Text with Alt+Enter, web forms=SUBSTITUTE(A2,CHAR(10)," ")
Carriage return13Windows files=SUBSTITUTE(A2,CHAR(13),"")
Tab9Text pasted from tables=SUBSTITUTE(A2,CHAR(9)," ")
Non-breaking space160Web pages=SUBSTITUTE(A2,UNICHAR(160)," ")
Zero-width space8203Web pages, chat apps=SUBSTITUTE(A2,UNICHAR(8203),"")
Byte order mark65279Start of some CSV files=SUBSTITUTE(A2,UNICHAR(65279),"")
Curly single quote8216, 8217Word, email=SUBSTITUTE(SUBSTITUTE(A2,UNICHAR(8216),"'"),UNICHAR(8217),"'")
Curly double quote8220, 8221Word, email=SUBSTITUTE(SUBSTITUTE(A2,UNICHAR(8220),""""),UNICHAR(8221),"""")
En and em dash8211, 8212Word, 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.

Try it on your own file

You start with 100 free credits. Every change is logged, and anything unclear is flagged, never guessed.

Fix a spreadsheet

Questions 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.

Keep reading

01Excel data cleaningHow to Clean Messy Excel Data: A Step-by-Step GuideThe fixed order that stops one fix from undoing another, with the formulas for every step.10 min read02Text and numbersHow to Keep Leading Zeros in Excel and CSV (ZIP Codes, IDs)Why Excel turns 02134 into 2134, how to get the zeros back, and how to stop it happening when you open a CSV.5 min read03CSV and importsHow to Clean a CSV File Before Importing It Into a CRMSeven fixes that prevent duplicate contacts, rejected rows and scrambled characters, and the 10-row test to run first.4 min read04DatesHow to Fix Dates in Excel and CSV Files (Mixed Formats)Text dates, day-month swaps, two-digit years and the one rule that makes dates safe to share.8 min read05Phone numbersHow to Fix Phone Numbers in Excel: Format and Country CodesLeading zeros, 9.19E+11, country codes and the international format that every system accepts.6 min read06DuplicatesHow to Remove Duplicates in Excel Without Losing DataExact, near and partial duplicates: decide what counts, mark before you delete, keep the best record.6 min read07DuplicatesHow to Find and Highlight Duplicates in ExcelFind repeats safely first: highlight them, count them, keep the first one, and spot the near-duplicates Excel does not see.3 min read08NamesHow to Standardize Names in Excel: Proper Case and ExceptionsWhat PROPER gets wrong, how to protect names that are already right, and how to flip "Smith, John" into "John Smith".4 min read09Email addressesHow to Fix Email Typos in Excel: gmial.com, .con and Missing @The typos that make campaigns bounce, and the formulas and checks that fix them without guessing.4 min read10Email addressesHow to Clean an Email List Before You Send a CampaignA five-step routine that removes the avoidable bounces from a list without deleting anyone you should keep.3 min read11NamesHow to Split Full Names into First and Last Name in ExcelFlash Fill, Text to Columns and formulas for splitting names, and the names that trip each one up.4 min read12Text cleanupHow to Remove Extra Spaces in Excel (TRIM, CLEAN and Non-Breaking Spaces)Why TRIM sometimes does nothing, and the one formula that removes every kind of stray space.3 min read14NumbersHow to Convert Text to Numbers in Excel (Numbers Stored as Text)Why sums show zero, why numbers sit on the left, and four ways to turn text back into real numbers.3 min read15Excel data cleaningHow to Clean Data with Power Query in Excel (Step by Step)Record your cleaning steps once and replay them on every new file, without formulas and without touching the original data.4 min read16Comparing dataHow to Compare Two Lists in Excel and Find What Is MissingFind the names, IDs or emails that are in one list and not the other, with formulas that scale.3 min read17CSV and importsFix Garbled Characters and Broken CSV Imports (UTF-8)UTF-8, delimiters, leading zeros, quotes and a checklist that makes a file safe to import.7 min read18Data entryData Entry Accuracy: How to Check, Measure and Improve ItWhat the research says about error rates, why proofreading fails and the checks that actually work.9 min read