Text Formulas

How to Remove Non-Printing Characters in Excel

Strip hidden line breaks, tabs and other non-printing characters from text with CLEAN, TRIM and SUBSTITUTE, and find out which ones are there.

On this page
  1. What non-printing characters are
  2. Use CLEAN for the basic ones
  3. Handle the non-breaking space
  4. Remove zero-width characters
  5. Find out which characters are there
  6. Keep line breaks when they matter
  7. Use Find and Replace for line breaks
  8. Convert the cleaned text to numbers

What non-printing characters are

Non-printing characters are codes that take up space but don’t show as a letter or number. They include line breaks, tabs and some kinds of space. They often come along when you copy text from a web page, a PDF, an email or another system. They can make a lookup fail or a count look wrong, even when the cell looks correct.

Use CLEAN for the basic ones

=CLEAN(A2) removes the first 32 non-printing characters in the ASCII set, codes 0 to 31. Those include line breaks and tabs.

To remove extra spaces as well, put CLEAN inside TRIM:

=TRIM(CLEAN(A2))

Handle the non-breaking space

A non-breaking space has code 160, and neither CLEAN nor TRIM removes it. Replace it with a normal space first, using UNICHAR(160):

=TRIM(SUBSTITUTE(CLEAN(A2),UNICHAR(160)," "))

SUBSTITUTE turns each non-breaking space into a normal space, and TRIM tidies up the result.

Remove zero-width characters

Some text includes zero-width characters, which take up no visible space. The zero-width space has code 8203. Replace it with nothing:

=SUBSTITUTE(A2,UNICHAR(8203),"")

Other invisible characters work the same way: find the code, then substitute it out.

Find out which characters are there

Excel has no function that lists the hidden characters in a cell, but two checks help:

  • =LEN(A2)-LEN(TRIM(CLEAN(A2))) counts the characters that CLEAN and TRIM would remove. A result above 0 means the cell has something to clean. It doesn’t count non-breaking spaces, so check for those separately.
  • =UNICODE(MID(A2,4,1)) returns the code of the character at position 4. Change the 4 to walk through the cell one character at a time.

Keep line breaks when they matter

CLEAN removes every line break. If a cell has line breaks you want to keep, such as a list of items on separate lines, don’t run CLEAN on it. Remove only the characters you don’t want, using SUBSTITUTE with a specific code.

Use Find and Replace for line breaks

To remove line breaks across a sheet in one pass, press Ctrl+H, click in Find what, and press Ctrl+J to enter a line break. Leave Replace with blank or type a space, then click Replace All. This changes the values directly, so keep a copy of the original first.

Convert the cleaned text to numbers

Cleaned numbers still hold text until you convert them. The steps are in how to convert text to number in excel. If the only problem is ordinary extra spaces, remove extra spaces in excel formula is a simpler place to start.

The complete guide to text formulas

Text Formulas in Excel Explained
Read the guide

Keep exploring

Guides from other topics

All topics →

How to Look Up Data in Excel

How lookups work in Excel, with VLOOKUP, XLOOKUP and INDEX with MATCH, how to set up your data, and how to choose the right function for the job.

Lookups 3 min read