In Excel: use =CLEAN(text) — it removes non-printable control characters, the invisible debris that survives a copy from a PDF or a mainframe export.
On this page8
Syntax
Arguments
| Argument | required / optional | Description |
|---|---|---|
text | required | Text to strip of non-printable characters (codes 0 to 31). |
Related functions
Add a helper column beside the imported text.
Type =TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " "))) to handle all three defect types at once.
Fill down, then compare =LEN of the original and the cleaned value to see how much came off.
Paste the helper column back over the original as values.
What this does
CLEAN strips the first 32 ASCII control characters — line feeds, carriage returns, tabs and similar — from text. Those arrive with PDF copies, mainframe extracts and web pastes, and they are invisible on screen while breaking every comparison and lookup against the column. Its important limitation is the non-breaking space, character 160, which is not in the range CLEAN removes and is the single most common culprit in web-pasted data. Removing that needs SUBSTITUTE(A2, CHAR(160), " "). The full repair for imported text is therefore all three: TRIM, CLEAN and that SUBSTITUTE. Keep the inputs visible and clearly labelled and the whole thing stays auditable — anyone who opens the file later, including you, can see at a glance exactly what feeds the result and change one assumption without hunting through the formula. Treat “excel clean function” as a small repeatable workflow rather than a one-off click you hope to remember next time. Use a small test block before the live file, so any surprise in the affected formula shows up while it is still harmless. When a formula is involved, keep the inputs labelled beside it, reference cells instead of typing values, and apply number formatting only after the result checks out. That turns a text operation that turns messy entries into clean, usable data into a method you can reuse, explain, and defend when the workbook leaves your screen.
A worked example
Removing line breaks that a PDF paste left inside cells: =CLEAN(A2) collapses them out. The complete import repair: =TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " "))) handles control characters, non-breaking spaces and padding in one pass. Diagnosing what is left: =CODE(LEFT(A2,1)) reveals the first character's number. CLEAN removes the invisible debris that makes two identical-looking values refuse to match, which is the hardest data problem to diagnose without it. Check the referenced cells, argument order and result type in your workbook. Start with the worked example before changing an input, then compare the changed result with the calculation you expected. An error value or a result of a different type is a reason to inspect the inputs and arguments.
In Google Sheets
Google Sheets support for this task has not been verified. Check the function, arguments and workflow in the target product before transferring the example. Matching formula notation does not establish identical behaviour. Nothing on this page is behind a login or a download: the exact answer is at the top, and the detail below it is there for when you need it. That is the whole promise here — the answer first, and just enough context to make it stick. For “excel clean function”, keep the input cells and the result visible while you check the formula in Excel. Follow the worked example and change one input at a time. The steps explain the workbook calculation; this page does not run a live calculator for that task.
Common mistakes
- Expecting CLEAN to remove non-breaking spaces; character 160 is outside its range and needs
SUBSTITUTE. - Using CLEAN alone where
TRIMwas also needed — the two remove different things. - Cleaning a column and leaving the helper formulas live, so the result still depends on the dirty source.
Frequently asked questions
How do I remove line breaks from cells?
=CLEAN(A2) removes them, or =SUBSTITUTE(A2, CHAR(10), " ") replaces them with a space if you want the words separated.
Why is there still an invisible character after CLEAN?
It is probably a non-breaking space (character 160), which CLEAN does not touch. Use SUBSTITUTE(A2, CHAR(160), " ").
What is the difference between CLEAN and TRIM?
CLEAN removes non-printable control characters; TRIM removes extra spaces. Imported data usually needs both.