Text functions
CLEAN and CHAR functions in Google Sheets and Excel
CLEAN removes line breaks and other non-printing characters, and CHAR returns the character for a code number.
CHAR returns the character with a given code number, such as CHAR(10) for a line break or CHAR(160) for a non-breaking space.
Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet
- Excel 2016
- Excel 2019
- Excel 2021
- Excel 2024
- Microsoft 365
- Google Sheets
Syntax
CLEAN(text)CHAR(number)Arguments in [brackets] are optional. In Google Sheets: CLEAN(text) and CHAR(table_number).
Example
=CLEAN(E5) reads: Return Tomás's city from E5 with the hidden line break removed.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Customer | Phone | Order | Amount | City | City |
| 2 | Okafor, Mara | +44 20 7946 0321 | ORD-2026-0412 | $1,250.00 | London | |
| 3 | Lind, Jonas | +46 40 123 456 | ORD-2026-0413 | $89.90 | Malmö | |
| 4 | Raman, Priya | +91 20 5550 1234 | ORD-2026-0419 | $2,040.00 | Pune | |
| 5 | Ruiz, Tomás | +34 954 000 111 | ORD-2026-0420 | $15.00 | Seville | Seville |
| 6 | Demir, Elif | +90 232 555 0199 | ORD-2026-0425 | $310.50 | Izmir | |
| 7 | Mori, Kenji | +81 6 5550 7788 | ORD-2026-0431 | $799.00 | Osaka |
F5 shows Seville without the line break that followed it.
How the spreadsheet calculates it
Removes non-printing characters (like line breaks from other systems) from E5.
- 1. CLEAN: Removes non-printing characters (like line breaks from other systems) from
E5.text=`E5`: the cell to clean
CHAR example
=SUBSTITUTE(E2,CHAR(160)," ") reads: In London's city cell E2, replace every non-breaking space (character 160) with a normal space, so TRIM can remove it afterwards.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Customer | Phone | Order | Amount | City | City |
| 2 | Okafor, Mara | +44 20 7946 0321 | ORD-2026-0412 | $1,250.00 | London | London |
| 3 | Lind, Jonas | +46 40 123 456 | ORD-2026-0413 | $89.90 | Malmö | Malmö |
| 4 | Raman, Priya | +91 20 5550 1234 | ORD-2026-0419 | $2,040.00 | Pune | Pune |
| 5 | Ruiz, Tomás | +34 954 000 111 | ORD-2026-0420 | $15.00 | Seville | Seville |
| 6 | Demir, Elif | +90 232 555 0199 | ORD-2026-0425 | $310.50 | Izmir | Izmir |
| 7 | Mori, Kenji | +81 6 5550 7788 | ORD-2026-0431 | $799.00 | Osaka | Osaka |
F2 shows London with a normal space at the end instead of a non-breaking one, which TRIM can now remove.
More CLEAN and CHAR examples
=TRIM(CLEAN(E2))Line breaks removed, then extra spaces.=LEN(E5)-LEN(CLEAN(E5))How many non-printing characters E5 holds.=IF(CLEAN(E5)=E5,"OK","Hidden characters")A check column that flags cells with hidden characters.=CLEAN(A2)&", "&CLEAN(E2)Two fields joined after cleaning both.=A2&CHAR(10)&E2Customer and city on two lines (with Wrap Text on).=TRIM(SUBSTITUTE(E2,CHAR(160)," "))Non-breaking spaces turned into normal ones, then trimmed.=SUBSTITUTE(E5,CHAR(10),", ")Line breaks replaced with a comma and a space.=CHAR(65)The letter A.
Paste any of these into the formula explainer to see it step by step.
Tips
- Combine the three for pasted text:
TRIM(CLEAN(SUBSTITUTE(E2,CHAR(160)," "))). - Use
CODEon a suspicious character to find its number before you remove it. - Clean once in a helper column and point every formula at the clean copy.
What CLEAN and CHAR are used for
Cleaning addresses, names and product data pasted from web pages, PDFs and other systems, so lookups, duplicate checks and counts stop failing on characters nobody can see.
Arguments
CLEAN
| Argument | Required | What it is |
|---|---|---|
| text | Yes | The text or cell to clean. |
CHAR
| Argument | Required | What it is |
|---|---|---|
| number | Yes | A code from 1 to 255. In Excel the character comes from your computer's character set; 10 is a line feed and 160 a non-breaking space.Watch out: A code outside 1 to 255 gives #VALUE!. |
Common mistakes
Expecting CLEAN to remove spaces: that's TRIM's job.
Expecting CLEAN to remove the non-breaking space from web pages: it removes only the first 32 non-printing codes (0 to 31), and the non-breaking space is code 160. Replace it with SUBSTITUTE and
CHAR(160).Cleaning a column and then comparing it with an uncleaned one: clean both sides of a lookup or a match.
Trying to type a non-breaking space into the formula: use CHAR(160).
Expecting a visible line break from
CHAR(10)without Wrap Text: the cell shows the parts run together until wrapping is turned on.Mixing up
CHARandCODE: CHAR turns a number into a character, CODE turns a character into its number.
In Google Sheets
Google Sheets has CLEAN(text), described as removing non-printable ASCII characters, and CHAR, which Google describes as using the current Unicode table. Codes above 127 can differ between the two apps, so test any CHAR above 127 in the app you use.
Errors you may see with CLEAN and CHAR
- #VALUE!: CHAR gets a code outside 1 to 255.
- #N/A: A lookup fails because one side still has a hidden line break or non-breaking space. How to fix it.
Questions
How do I remove line breaks from a cell?
CLEAN(E5) removes them. To turn them into spaces instead of joining the words, replace the line-break character: SUBSTITUTE(E5,CHAR(10)," ").
Why doesn't TRIM remove all the spaces?
Text copied from web pages often contains non-breaking spaces (code 160), which TRIM and CLEAN both ignore. Turn them into normal spaces first: TRIM(SUBSTITUTE(E2,CHAR(160)," ")). See the clean text guide.
How do I find out which hidden character is in a cell?
Read its code with CODE: CODE(RIGHT(E2,1)) gives 160 for the last character of London on this sheet, a non-breaking space.
How do I put a line break inside a formula's result?
Join CHAR(10) between the parts, like A2&CHAR(10)&B2, and turn on Wrap Text for the cell so the break shows.
Sources
Official documentation the facts on this page were checked against.