Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Google Sheets CLEAN Function: How to Use It

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The CLEAN function in Google Sheets removes non-printable characters from a text string, such as line breaks, tabs, and other control characters that can break formulas, lookups, and imports. To use it, type =CLEAN(text) in a cell, where text is the cell reference or string you want to clean, and press Enter. The result is a clean version of the text with those invisible characters stripped out.

What You'll Need

  • A Google account with access to Google Sheets (free with any Google account).
  • A spreadsheet containing text that may include hidden characters, or a sample string to test with.
  • Basic familiarity with entering formulas in a cell.

Step-by-Step

  1. Open your spreadsheet. Go to Google Sheets and open the file that contains the text you want to clean. If you are starting fresh, create a new blank spreadsheet.
  2. Identify the cell with the problem text. Click the cell that holds the text with hidden characters. Common signs include line breaks inside a cell, extra spaces that will not trim, or text that fails to match in VLOOKUP or COUNTIF. Note the cell reference (for example, A2).
  3. Pick an empty cell for the result. Click an empty cell where you want the cleaned text to appear, such as B2. This keeps the original data intact while you work.
  4. Enter the CLEAN formula. Type =CLEAN(A2) (replace A2 with your actual cell reference) and press Enter. The cell now shows the text with non-printable characters removed.
  5. Check the result. Compare the original and cleaned cells. If the original had a line break (often inserted with Ctrl+Enter or Alt+Enter), the cleaned version should now be a single line. If the original had tabs or other control characters, they should be gone.
  6. Copy the formula down. If you have a column of text to clean, click the cell with the formula, then drag the small square handle at the bottom-right corner down over the rows you need. Alternatively, double-click the handle to fill down automatically to the end of the adjacent data.
  7. Convert formulas to values (optional). If you want to replace the original text with the cleaned version, select the cleaned cells, press Ctrl+C (or Cmd+C on Mac), then use Edit > Paste special > Values only to paste the results. You can then delete the original column if no longer needed.
  8. Combine CLEAN with TRIM for extra tidiness. CLEAN removes non-printable characters but does not remove extra spaces. To also collapse multiple spaces into one and remove leading/trailing spaces, use =TRIM(CLEAN(A2)). This is useful when data comes from copied web pages or exported CSVs.
  9. Test with a sample string. If you are unsure what CLEAN does, type =CLEAN("Hello"&CHAR(10)&"World") in an empty cell. CHAR(10) inserts a line break; the result should be "HelloWorld" without the break. This confirms the function is working as expected.

Common Mistakes

  • Expecting CLEAN to remove all spaces. CLEAN only removes non-printable characters (ASCII codes 0–31). It does not remove regular spaces, non-breaking spaces (CHAR(160)), or other printable whitespace. Use TRIM for spaces, and SUBSTITUTE for non-breaking spaces.
  • Forgetting that CLEAN works on text only. If the cell contains a number, CLEAN converts it to text. This can affect calculations later. Apply CLEAN only to text fields.
  • Overwriting original data without a backup. Pasting values over the original column destroys the source data. Always keep a copy or work in a new column until you are sure.
  • Assuming CLEAN fixes formatting. CLEAN does not change font, alignment, or cell formatting. It only affects the characters in the string.
  • Using CLEAN on a range without array formula. In Google Sheets, =CLEAN(A2:A10) in a single cell will only process the first cell unless you use an array formula like =ARRAYFORMULA(CLEAN(A2:A10)). Otherwise, fill down manually.

Tips

  • Use =TRIM(CLEAN(A2)) as a standard cleanup combo for imported data.
  • To remove non-breaking spaces (common in web copy), use =SUBSTITUTE(CLEAN(A2),CHAR(160)," ") then TRIM.
  • If you need to clean an entire column in place, consider using a helper column, then copy values back after verifying.
  • CLEAN is often used before VLOOKUP or MATCH to ensure text matches exactly.
  • For data imported from other systems, CLEAN can remove line breaks that cause rows to split incorrectly.

Troubleshooting

If CLEAN does not seem to work, check these common issues:

  • The formula returns the same text. The cell may not contain non-printable characters. Use =LEN(A2) before and after to see if the length changed. If not, the problem is likely spaces or non-breaking spaces, not control characters.
  • You see #NAME? error. This means the function name is misspelled or not recognized. Ensure you typed =CLEAN( with no spaces before the parenthesis.
  • You see #VALUE! error. The argument may be a range instead of a single cell. CLEAN expects a single text value; use ARRAYFORMULA for ranges.
  • Text still looks wrong after CLEAN. There may be other characters like non-breaking spaces or zero-width spaces. Use SUBSTITUTE with CHAR(160) or CHAR(8203) as needed.
  • Formula not updating. Check that automatic recalculation is on (File > Settings > Calculation). If set to manual, press Ctrl+R to recalculate.

Frequently Asked Questions

What characters does CLEAN remove?

CLEAN removes non-printable ASCII characters with codes 0 through 31, which include line breaks, tabs, carriage returns, and other control characters. It does not remove regular spaces or printable characters.

Does CLEAN remove spaces?

No. CLEAN only removes non-printable characters. To remove extra spaces, use TRIM. To remove all spaces, use SUBSTITUTE.

Can I use CLEAN on a range of cells?

Yes, but you need to use an array formula: =ARRAYFORMULA(CLEAN(A2:A10)). Without ARRAYFORMULA, only the first cell in the range is processed.

Why is CLEAN not removing line breaks?

Line breaks in Google Sheets are typically CHAR(10). CLEAN should remove them. If it does not, the line break may be a different character, such as CHAR(13) (carriage return). You can remove both with =CLEAN(SUBSTITUTE(A2,CHAR(13),"")) or use REGEXREPLACE.

Is CLEAN available in Excel too?

Yes, Excel has a CLEAN function with similar behavior. The syntax is the same: =CLEAN(text).

Can CLEAN remove non-breaking spaces?

No. Non-breaking spaces (CHAR(160)) are printable characters, so CLEAN leaves them. Use SUBSTITUTE(A2,CHAR(160)," ") to replace them with regular spaces, then TRIM.