Practice free

CLEAN function

CLEAN strips invisible control characters, such as stray line feeds and tabs, that come along when you paste data from other systems. It is often paired with TRIM when cleaning imports.

Example

Read it as a sentence: join a, the invisible character with code 7, and b, then strip out the nonprinting character, which leaves ab.

Practice this in the app

Syntax

CLEAN(text)

text (required)
The text to strip of non-printing characters.

Returns: The text with control characters (codes 0 to 31) removed.

What Excel actually returns

Each formula below was run in desktop Excel. The result is exactly what the cell showed, errors included.

FormulaExcel showsCase
=CLEAN("a"&CHAR(10)&"b") ab Removes line feed
=LEN(CLEAN(CHAR(160)&"x")) 2 Non-breaking space kept?
=LEN(CLEAN(CHAR(127)&"x")) 2 DEL character
=LEN(CLEAN(UNICHAR(129)&"x")) 1 Unicode control 129
=CLEAN(123) 123 Number
=CLEAN(Data!F5) #DIV/0! Error input

The Data sheet these formulas read

A cell that starts with = holds that formula.

Watch out for

  • Does not remove non-breaking spaces (code 160); use SUBSTITUTE(text,CHAR(160)," ") for those.
  • Also removes legitimate line breaks.

Where it works

Excel
CLEAN is in every version of Excel from 2007 on.
Google Sheets
Same name, same behaviour for everyday use.

Part of Text functions. Every result on this page was measured in desktop Excel, build 16.0.20527. Last updated .