formulastreak

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

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.

CRM export · edit F5 and watch it recalculate
Click a cell (or use the arrow keys) to insert its address · Enter shows the resultF5 = Seville
ABCDEF
1CustomerPhoneOrderAmountCityCity
2Okafor, Mara+44 20 7946 0321ORD-2026-0412$1,250.00London 
3Lind, Jonas+46 40 123 456ORD-2026-0413$89.90Malmö
4Raman, Priya+91 20 5550 1234ORD-2026-0419$2,040.00 Pune
5Ruiz, Tomás+34 954 000 111ORD-2026-0420$15.00Seville Seville
6Demir, Elif+90 232 555 0199ORD-2026-0425$310.50Izmir
7Mori, Kenji+81 6 5550 7788ORD-2026-0431$799.00Osaka  

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. 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.

CRM export · edit F2 and watch it recalculate
Click a cell (or use the arrow keys) to insert its address · Enter shows the resultF2 = London
ABCDEF
1CustomerPhoneOrderAmountCityCity
2Okafor, Mara+44 20 7946 0321ORD-2026-0412$1,250.00London London
3Lind, Jonas+46 40 123 456ORD-2026-0413$89.90MalmöMalmö
4Raman, Priya+91 20 5550 1234ORD-2026-0419$2,040.00 Pune Pune
5Ruiz, Tomás+34 954 000 111ORD-2026-0420$15.00Seville Seville
6Demir, Elif+90 232 555 0199ORD-2026-0425$310.50IzmirIzmir
7Mori, Kenji+81 6 5550 7788ORD-2026-0431$799.00Osaka  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 CODE on 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

ArgumentRequiredWhat it is
textYesThe text or cell to clean.

CHAR

ArgumentRequiredWhat it is
numberYesA 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 CHAR and CODE: 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.

Practise CLEAN and CHAR on a live sheet

Lesson 30, SUBSTITUTE, CLEAN and invisible spaces (Unit 8, Cleaning text at scale), has 6 graded exercises, checked instantly, with steps and hints when you're stuck. Pro