Example 1
Remove a hidden line break
C2 =CLEAN(A2)
Result: FX-1010
A2 ends with a line break that you can't see. CLEAN removes it.
C2 =CLEAN(A2) returns FX-1010
Removes non-printing characters, such as line breaks and tabs, from text.
Syntax
=CLEAN()
All versions of Excel.
Try it
Edit the formula in C2 or change the inputs. The sheet recalculates as you type.
C2 =CLEAN(A2) returns FX-1010
CLEAN removes non-printing characters from text. These are control characters, such as line breaks and tabs, that come along when you paste from emails, web pages, PDFs or other systems. They are often invisible, or show as small boxes, and they break lookups and comparisons in the same way a stray space does.
CLEAN deletes characters with codes 0 to 31. The two you will meet most are:
=CLEAN("FX-1010" & CHAR(10)) returns FX-1010, and the hidden line break is gone.
CLEAN does not remove ordinary spaces, so use TRIM for those. It does not remove non-breaking spaces, character 160, either. Convert them with SUBSTITUTE: =SUBSTITUTE(A2,UNICHAR(160)," "). A few other non-printing characters exist outside the first 32 codes, such as character 127. CLEAN leaves them as they are.
CLEAN deletes a line break, it doesn't replace it with a space. =CLEAN("Pallet" & CHAR(10) & "wrap") returns Palletwrap. When a line break separates words, replace it with a space instead: =SUBSTITUTE(A2,CHAR(10)," "). Then apply TRIM if the break was next to other spaces.
For text of unknown origin, a full clean runs all three steps:
=TRIM(CLEAN(SUBSTITUTE(A2,UNICHAR(160)," ")))
Read it from the inside: non-breaking spaces become ordinary spaces, non-printing characters are removed, and extra spaces are trimmed.
Compare lengths. =LEN(A2)-LEN(CLEAN(A2)) returns the number of non-printing characters CLEAN removes. A result above 0 means the cell has some. =CODE(RIGHT(A2,1)) shows the code of the last character, which reveals what it is: 10 for a line break, 9 for a tab, 32 for a space.
Like the other text functions, CLEAN returns text. A cleaned "1250" is not a number until you convert it with VALUE. Applying CLEAN to a real number turns it into text, so keep it to text columns.
Use CLEAN on imported data before a lookup, a match or a duplicate check. Use it on text you are about to put in a CSV or a system that does not accept line breaks. Do not use it on text where the line breaks are wanted, such as an address block, or you will lose the formatting.
A2. CLEAN removes the first 32 non-printing characters (character codes 0 to 31) and leaves everything else, including spaces.Each example is a live sheet. Change the inputs or the formula and watch the result.
Example 1
C2 =CLEAN(A2)
Result: FX-1010
A2 ends with a line break that you can't see. CLEAN removes it.
C2 =CLEAN(A2) returns FX-1010
Example 2
C2 =LEN(A2)-LEN(CLEAN(A2))
Result: 2
A tab and a line break, two characters, are removed by CLEAN.
C2 =LEN(A2)-LEN(CLEAN(A2)) returns 2
Example 3
C2 =SUBSTITUTE(A2,CHAR(10)," ")
Result: Pallet wrap
CLEAN would give "Palletwrap" because it deletes the break. SUBSTITUTE swaps it for a space.
C2 =SUBSTITUTE(A2,CHAR(10)," ") returns Pallet wrap
Example 4
C2 =TRIM(CLEAN(SUBSTITUTE(A2,UNICHAR(160)," ")))
Result: Floor cleaner
SUBSTITUTE fixes the non-breaking space, CLEAN removes the tab, and TRIM removes the leading space.
C2 =TRIM(CLEAN(SUBSTITUTE(A2,UNICHAR(160)," "))) returns Floor cleaner
Solve it in the sheet. Every answer is checked, with hints if you need them.
Task 1 of 2
In B2, return the code in A2 without its hidden line break or tab. Fill it down to B5.
Answer in B2, then it fills down to B5.
SUBSTITUTE(A2,CHAR(10)," ").CODE(RIGHT(A2,1)).To delete them, use `=CLEAN(A2)`. To replace them with a space, use `=SUBSTITUTE(A2,CHAR(10)," ")`, which stops the words on either side from running together.
CLEAN removes non-printing characters such as line breaks and tabs. TRIM removes extra spaces. For messy data, use `=TRIM(CLEAN(A2))`.
The space may be a non-breaking space (character 160), which CLEAN and TRIM both leave alone. Use `=SUBSTITUTE(A2,UNICHAR(160)," ")` first.
Compare `=LEN(A2)` with `=LEN(CLEAN(A2))`. A difference means CLEAN found non-printing characters. `=CODE(RIGHT(A2,1))` shows what the last character is.
It accepts them, but it returns the number as text. Use it on text columns, and convert the result with VALUE if you need a number.
CLEAN is taught in Logic and text, lesson 7: TRIM and CLEAN. Each lesson is a short, graded exercise like the one above.