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)| Argument | What it means | |
|---|---|---|
text | Required | The 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
| A | B | |
|---|---|---|
| 1 | ||
| 2 | Invoice#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
| A | B | |
|---|---|---|
| 1 | ||
| 2 | 2 |
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
| A | B | |
|---|---|---|
| 1 | Product (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.
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.
| Language | Function name |
|---|---|
| Czech | VYČISTIT |
| Danish | RENS |
| Dutch | WISSEN.CONTROL |
| Finnish | SIIVOA |
| French | EPURAGE |
| German | SÄUBERN |
| Hungarian | TISZTÍT |
| Italian | LIBERA |
| Norwegian (Bokmål) | RENSK |
| Polish | OCZYŚĆ |
| Portuguese (Brazil) | TIRAR |
| Portuguese (Portugal) | LIMPARB |
| Russian | ПЕЧСИМВ |
| Spanish | LIMPIAR |
| Swedish | STÄDA |
| Turkish | TEMİZ |