Text function

CLEAN function

Removes non-printing control characters (codes 0-31), such as line breaks and tabs, from text copied out of other systems.

Available in All versions of Excel, including Microsoft 365, Excel for Mac and Excel for the web

In every Excel versionWorks in Google Sheets

Syntax

CLEAN(text)
ArgumentWhat it means
textRequiredThe text or cell to clean.

Returns: The text with all characters whose code is 0-31 removed.

How CLEAN works

Text exported from accounting packages, web pages or old mainframe reports often carries invisible control characters: line feeds, carriage returns, tabs or stranger codes. They break lookups, make cells look oddly tall and confuse LEN. CLEAN deletes every character whose code is between 0 and 31, which covers all of those.

CLEAN does not touch normal spaces, and it does not remove a few other troublemakers that live above code 31: the non-breaking space (code 160, very common in web data), and the Unicode control characters 127, 129, 141, 143, 144 and 157. That is why the classic cleaning recipe combines three functions: SUBSTITUTE swaps the non-breaking spaces for normal spaces, CLEAN removes control codes, and TRIM removes leading, trailing and doubled spaces.

Because CLEAN removes the line break completely, words that were on separate lines can end up glued together. If you want a space instead, replace the line break with SUBSTITUTE first: =SUBSTITUTE(A2,CHAR(10)," ").

Examples

1Remove a line break from an invoice label

B2fx=CLEAN("Invoice"&CHAR(10)&"#4471")
AB
1
2Invoice#4471

Result: Invoice#4471

The formula builds a label with a hidden line feed in the middle (as an export might). CLEAN removes it, so the two parts are joined directly.

2See how many hidden characters were removed

B2fx=LEN("Order"&CHAR(13)&CHAR(10)&"123")-LEN(CLEAN("Order"&CHAR(13)&CHAR(10)&"123"))
AB
1
22

Result: 2

The text contains a Windows line ending (carriage return + line feed). The original is 10 characters long, the cleaned version 8, so 2 invisible characters were removed.

3Full cleaning recipe for web data

B2fx=TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160)," ")))
AB
1Product (copied from web)
2  Laptop  Stand Laptop Stand

Result: Laptop Stand

A2 contains non-breaking spaces (code 160) that CLEAN and TRIM alone would leave. SUBSTITUTE turns them into normal spaces, CLEAN removes any control codes and TRIM tidies the spacing.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 15 KB

Tips

  • CLEAN works on text only; numbers pass through and are returned as numbers.
  • If a lookup still fails after CLEAN and TRIM, check the first character with =CODE(LEFT(A2)) and the last with =CODE(RIGHT(A2)) to find the culprit.
  • In Power Query the Transform > Format > Clean command does the same job for a whole column before the data reaches the sheet.

Google Sheets

CLEAN also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.

CLEAN in other languages

In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.

LanguageFunction name
CzechVYČISTIT
DanishRENS
DutchWISSEN.CONTROL
FinnishSIIVOA
FrenchEPURAGE
GermanSÄUBERN
HungarianTISZTÍT
ItalianLIBERA
Norwegian (Bokmål)RENSK
PolishOCZYŚĆ
Portuguese (Brazil)TIRAR
Portuguese (Portugal)LIMPARB
RussianПЕЧСИМВ
SpanishLIMPIAR
SwedishSTÄDA
TurkishTEMİZ

Recipes that use CLEAN