Templates, guides & honest tool reviews for small business

Sunday, November 29, 2026

Remove Extra Spaces in Excel: TRIM, CLEAN and SUBSTITUTE Explained

Remove extra spaces in Excel with TRIM
Illustration: Remove extra spaces in Excel

To remove extra spaces in Excel, use the TRIM function: =TRIM(A2). It deletes spaces at the start and end of the text and reduces any run of spaces between words to one. That fixes most lookups that fail for no visible reason and most counts that are too high. This guide covers TRIM, the non-breaking space that TRIM misses, Find and Replace for removing all spaces, and how to keep the cleaned values. The sample data is made up.

Why extra spaces cause problems

"Ann" and "Ann " look the same on screen, but Excel sees two different texts. A VLOOKUP or XLOOKUP on the first will not find the second. COUNTIF, remove duplicates and pivot tables also treat them as different items. If a lookup returns #N/A and the values look identical, a hidden space is a common cause. Our guide to fixing a VLOOKUP that returns #N/A lists the other causes.

Remove extra spaces with TRIM

=TRIM(text)

Put the formula in a helper column next to your data. If the name is in A2, type =TRIM(A2) in B2 and fill down. TRIM removes leading spaces, trailing spaces and extra spaces between words, but it keeps one normal space between words.

To check how many characters were removed, compare lengths: =LEN(A2)-LEN(TRIM(A2)). A result above 0 means the cell had extra spaces.

TRIM function in Excel removes leading and trailing spaces
Made-up names (illustration).

Replace the original data with the cleaned values

The TRIM result is a formula, so it depends on the original column. To keep only the clean text:

  1. Select the TRIM results and copy them.
  2. Right click the first cell of the original column.
  3. Under Paste Options choose Values.
  4. Delete the helper column.
Paste values to replace the original data after TRIM in Excel
Four steps (illustration).

When TRIM does not work: the non-breaking space

Text copied from websites often contains a non-breaking space, which is character 160. TRIM only removes the normal space, character 32. Replace the character first:

=TRIM(SUBSTITUTE(A2, CHAR(160), " "))

SUBSTITUTE turns each non-breaking space into a normal one, and TRIM then cleans it up. If LEN shows extra characters but TRIM changes nothing, this is the likely reason.

Remove a non-breaking space in Excel with SUBSTITUTE and CHAR 160
TRIM alone misses character 160 (illustration).

Remove line breaks and hidden characters with CLEAN

CLEAN removes non-printing characters, such as line breaks, that often arrive with imported data. Use both together:

=TRIM(CLEAN(A2))

Note that CLEAN does not remove the non-breaking space, so combine all three functions when the data is messy: =TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " "))).

Remove all spaces, not only extra ones

Sometimes you want no spaces at all, for example in a product code like "AB 123 C". Use SUBSTITUTE:

=SUBSTITUTE(A2, " ", "")

Without a formula, use Find and Replace. Press Ctrl+H, type one space in "Find what", leave "Replace with" empty and click Replace All. This changes the selected cells directly and cannot be undone after you save and close, so work on a copy.

Which Excel formula removes extra, hidden or all spaces
Pick by problem (illustration).

Clean a column in Power Query

If you import the same file every week, clean it in Power Query. Select the column, go to Transform, then Format, then Trim. Power Query remembers the step, so the next refresh cleans the new data too. The Trim step in Power Query removes leading and trailing spaces. It does not shrink spaces between words, so test it on your data.

Fix numbers that are stored as text

Extra spaces in a number cell make Excel treat it as text. After trimming, convert it: =VALUE(TRIM(A2)). Related text cleanup is covered in our guide to the LEFT, RIGHT and MID functions, and the TEXT function helps when you need the cleaned number shown in a set format.

Common mistakes

  • Trimming in place. A formula cannot overwrite its own cell. Use a helper column.
  • Forgetting to paste values. If you delete the original column first, the formulas show #REF!.
  • Using Replace All on a column with real spaces between words. It removes those too.
  • Assuming TRIM handles every space. It does not touch character 160.

Questions and answers

Does TRIM remove spaces between words?

It reduces several spaces between words to a single space. It never removes the last single space between two words.

How do I remove only leading spaces?

TRIM removes both leading and trailing spaces. If you need only the leading ones removed, use a formula that finds the first non-space character, or accept TRIM when trailing spaces do no harm.

Why does my cell still look different after TRIM?

It may contain a non-breaking space or a hidden character. Try SUBSTITUTE with CHAR(160) and CLEAN as shown above.

Is there a TRIM function in Google Sheets?

Yes, TRIM works the same way in Google Sheets. You can apply it to a whole column with ARRAYFORMULA.

العربية