Skip to content

Lesson 73 of 92 · Free Excel Course

Excel · Excel function reference

Excel CLEAN Function: Syntax, Examples and Common Errors

How the Excel CLEAN function removes line breaks, tabs and other non-printing characters, and what it misses (CHAR(160), extra spaces). Free practice file.

The CLEAN function strips non-printing characters out of text and returns what's left. These are invisible control codes, such as tabs, line breaks and carriage returns, that sneak in with data imported from other programs, CSV files and web pages. You can't see them, but they make text longer than it looks, stop lookups from matching and keep numbers from adding up. CLEAN works in Excel for Microsoft 365 (Windows and Mac), Excel for the web, and Excel 2024, 2021, 2019 and 2016.

Syntax

=CLEAN(text)
  • text (required): the text to clean. It can be a cell reference such as A2, text in quotes or another formula. If you give it a number, CLEAN returns that number as text.

Microsoft is precise about what CLEAN removes: the first 32 non-printing characters of the 7-bit ASCII code, values 0 through 31. That range includes the tab (9), the line break you get with Alt+Enter (10) and the carriage return (13). Microsoft also warns that Unicode has other non-printing characters, values 127, 129, 141, 143, 144 and 157, that CLEAN does not remove on its own. And it never removes spaces, including the non-breaking space (160).

CLEAN doesn't change the original cell. It returns a cleaned copy, usually in a helper column next to the data.

Examples

1. Microsoft's example. On Microsoft's CLEAN page, cell A2 holds =CHAR(9)&"Monthly report"&CHAR(10): a tab, the words, then a line break. CLEAN returns just the words. LEN shows the two hidden characters going away.

B2=CLEAN(A2)
ABCD
1DataCleanedLEN beforeLEN after
2Monthly reportMonthly report1614
A2 looks like plain text but holds 16 characters: 14 letters and spaces plus a tab and a line break. C2 is =LEN(A2) and D2 is =LEN(B2).

Using LEN before and after is the easiest way to prove CLEAN did something, because the text looks identical either way. The LEN function page has more on counting hidden characters.

2. Line breaks from an imported address. Address and comment fields often arrive with a line break between lines. CLEAN removes it, but with nothing in its place, so the lines run together. When you want a separator, swap the break with SUBSTITUTE instead.

C2=SUBSTITUTE(A2,CHAR(10),", ")
ABC
1Imported address=CLEAN(A2)Line break to comma
212 Oak St / Austin, TX12 Oak StAustin, TX12 Oak St, Austin, TX
The / marks where the line break sits in A2 (Excel shows two lines). CLEAN glues St and Austin together; SUBSTITUTE puts a comma and space there.

Some files use a carriage return plus a line break (CHAR(13) then CHAR(10)) at the end of each line. Run SUBSTITUTE for CHAR(10) first, then CLEAN to mop up any leftover CHAR(13): =CLEAN(SUBSTITUTE(A2,CHAR(10),", ")).

3. Text copied from a web page. This is where CLEAN surprises people. A2 holds " Widget" with a normal space in front and a non-breaking space (CHAR(160)) at the end, which web pages use a lot. =TRIM(CLEAN(A2)) looks right but is still 7 characters long, because neither function touches character 160.

C3=TRIM(SUBSTITUTE(CLEAN(A3),CHAR(160)," "))
ABCD
1Web textFormulaResultLEN
2 Widget=TRIM(CLEAN(A2))Widget7
3 Widget=TRIM(SUBSTITUTE(CLEAN(A2),CHAR(160)," "))Widget6
Both results look the same, but only row 3 is really 6 characters. SUBSTITUTE turns the non-breaking space into a normal one, and TRIM then removes it.

That combined formula is the one to remember for any messy import: CLEAN for control characters, SUBSTITUTE for non-breaking spaces, TRIM for extra spaces. If you're not sure which character is causing trouble, =CODE(RIGHT(A2)) shows the code of the last character: 160 means a non-breaking space, 10 a line break, 13 a carriage return. On a Mac, CHAR and CODE use the Mac character set, so code 160 is a different character there: use UNICHAR(160) and =UNICODE(RIGHT(A2)) instead, which work the same on Windows too.

4. A number that won't add up. A2 holds 125 followed by a carriage return, as can happen with data exported from another system. Excel treats it as text, so SUM ignores it. CLEAN removes the character but still returns text; VALUE turns it into a number.

C2=VALUE(CLEAN(A2))
ABCD
1Imported=CLEAN(A2)=VALUE(CLEAN(A2))Times 2
2125125125250
B2 is cleaned text (left-aligned in Excel); C2 is a real number (right-aligned), so D2 =C2*2 gives 250.

Common errors

  • Nothing seems to change. The problem character isn't in the 0 to 31 range. A non-breaking space needs SUBSTITUTE(A2,CHAR(160)," "). For the other characters Microsoft lists (127, 129, 141, 143, 144 and 157), remove them with SUBSTITUTE too, for example =SUBSTITUTE(A2,UNICHAR(129),""). Use CODE to find the culprit.
  • Extra spaces are still there. CLEAN doesn't remove spaces. Add TRIM: =TRIM(CLEAN(A2)).
  • Words are joined together. CLEAN deleted a line break. Replace CHAR(10) with a space or comma first (example 2).
  • The result won't calculate. CLEAN returns text, even for digits. Wrap it in VALUE (example 4).
  • The original data is still messy. CLEAN only returns a copy. To replace the originals, copy the cleaned column, then use Paste Special > Values over the old one and delete the helper column.
  • #NAME? or another error. #NAME? means the name is misspelled. If the cell CLEAN reads holds an error such as #N/A, CLEAN returns that same error; fix the source.

A cell that looks empty but holds only a stray control character isn't blank to Excel, so ISBLANK returns FALSE and COUNTA counts it. =LEN(TRIM(CLEAN(A2)))=0 tests for "empty once cleaned"; see ISBLANK and logic checks.

Related functions

Try it yourself

Download the practice workbook. The text in column A is built with CHAR, so the hidden characters are really there: click a cell and look at the formula bar. Clean Microsoft's example, fix an address with a line break, strip a non-breaking space from web text and turn an imported number back into a number, then check the Answers sheet.

Frequently asked questions

What does the CLEAN function do in Excel?

CLEAN removes non-printing characters from text: the first 32 codes of the 7-bit ASCII set (0 to 31), which include tabs (CHAR(9)), line breaks (CHAR(10)) and carriage returns (CHAR(13)). These often come along with data imported from other programs, web pages or CSV files. It returns the cleaned text and leaves the original cell unchanged.

What is the difference between CLEAN and TRIM?

They fix different problems. CLEAN removes invisible control characters such as line breaks and tabs, but leaves spaces alone. TRIM removes extra spaces (at the ends, and doubles between words) but not control characters. Use both together: =TRIM(CLEAN(A2)).

Why doesn't CLEAN remove all the spaces?

CLEAN doesn't touch spaces at all. And the non-breaking space found in text copied from web pages is character 160, outside the 0 to 31 range CLEAN covers. Swap it for a normal space and trim: =TRIM(SUBSTITUTE(CLEAN(A2),CHAR(160)," ")).

How do I remove line breaks in Excel without joining the words?

CLEAN deletes the line break with nothing in its place, so two lines run together. Replace it instead: =SUBSTITUTE(A2,CHAR(10)," ") puts a space where each break was, or use ", " to get a comma and space.

Why is my number still not adding up after CLEAN?

CLEAN always returns text, so a cleaned "125" is still text. Wrap it in VALUE to get a real number: =VALUE(CLEAN(A2)).