How to Remove Extra Spaces in Excel (TRIM Function)

Office and email troubleshooting category image

Extra spaces in Excel can be invisible but still break lookups, IF comparisons, joins, and duplicate checks. TRIM is the usual cleanup tool because it removes spaces at the beginning and end of text and reduces repeated internal spaces to one.

Does this affect you?

Use this for Excel for Microsoft 365, Excel 2021, Excel 2019, and Excel for the web when copied text from websites, PDFs, emails, exports, or forms does not match correctly.

Remove extra spaces with TRIM

Use a helper column so you can check the cleaned result before replacing data.

  1. Click a blank cell beside the messy text.
  2. Type =TRIM(A2), changing A2 to your first source cell.
  3. Press Enter.
  4. Fill the formula down the column.
  5. Select the cleaned helper column and copy it.
  6. Right-click the original column and use Paste Special > Values.
  7. Delete the helper column after confirming the results.

TRIM keeps one normal space between words. That is usually what you want for names, addresses, titles, and sentences.

Remove every space

Use SUBSTITUTE only when spaces should not exist at all, such as in codes or phone-style strings.

  1. In a helper cell, enter =SUBSTITUTE(A2,” “,””).
  2. Fill the formula down.
  3. Copy the results.
  4. Paste Special > Values over the original cells or into a final output column.

More control

Fix non-breaking spaces

Text copied from the web may contain non-breaking spaces that look normal but are not removed by TRIM. Use SUBSTITUTE with CHAR(160), then TRIM the result, such as =TRIM(SUBSTITUTE(A2,CHAR(160),” “)).

Use Flash Fill for a short list

Type the corrected version of the first one or two cells beside the messy data, then press Ctrl+E or use Data > Flash Fill. Excel fills the pattern for the remaining rows.

Check with LEN

Compare LEN before and after cleanup. If the length does not change, the problem may be a non-breaking space or another hidden character. CLEAN can help remove some non-printing characters.

Sources

  • Microsoft Support – TRIM function (2025)
  • Microsoft Support – SUBSTITUTE function (2025)
  • Microsoft Support – Flash Fill in Excel (2025)
Disclosure: This post may contain affiliate links which means I may receive a commission for purchases made through links. I will only recommend products that I have personally used! Learn more on my Private Policy page.
A thoughtful woman reads a newspaper while enjoying coffee at an indoor workspace.

DEALWEEK

SUBSCRIBE AND GET 20% OFF YOUR NEXT ORDER! OFFER ENDS SOON - DON’T MISS OUT!

We don’t spam! Read our privacy policy for more info.

Shopping Cart