Excel beginner

How to Clean Text by Removing Extra Spaces?

Extra spaces and non-printable characters can clutter your data. This formula helps you clean it up effectively.

Formula Genius can generate a draft from a plain-English prompt. Supported formulas can be checked with sample cases; review the coverage on the result.

The formula

Prompt

"Remove extra spaces from the beginning, end, and middle of text, and remove non-printable characters"

Excel
=CLEAN(TRIM(A1))

This formula removes extra spaces and non-printable characters from a given text string.

Step-by-step breakdown

  1. TRIM(A1) removes leading and trailing spaces from the text in cell A1.
  2. CLEAN(...) removes non-printable characters from the result of the TRIM function.
  3. The final output is a clean version of the original text.
  4. You can replace A1 with any cell reference containing the text you want to clean.

Edge cases & warnings

  • Text with only spaces will return an empty string.
  • Text with multiple spaces between words will return a single space between them.
  • Non-printable characters may not be visible but will be removed.
  • Leading and trailing spaces will be completely eliminated.

Examples

Prompt

" Hello World! "

Excel
Hello World!
Prompt

"Text with non-printable char"

Excel
Text with non-printable char

Frequently asked questions

What does the TRIM function do?

The TRIM function removes extra spaces from text except for single spaces between words.

Can I use this formula for numbers?

This formula is designed for text; numbers should be cleaned differently.

What if my text has special characters?

Special characters will remain; this formula only targets spaces and non-printable characters.

Can't find what you need?

Describe a formula in plain English. Formula Genius drafts and explains it, and can check supported formulas on sample cases.