Smart Systems for Home

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

Removing Trailing Spaces in Excel: Step-by-Step

· 6 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

To remove trailing spaces in Excel, the fastest reliable method is the TRIM function: put =TRIM(A2) in an empty column next to your data, fill it down, then copy the results and paste them back over the originals using Paste Special > Values. Trailing spaces look invisible but break VLOOKUP, COUNTIF, conditional formatting and filters, so cleaning them is worth the minute it takes. TRIM removes leading and trailing spaces and collapses runs of multiple spaces between words into one. There is one catch it cannot solve by itself: TRIM only strips the regular space character (code 32), not non-breaking spaces (code 160) copied from web pages or PDFs. Those need SUBSTITUTE.

What You'll Need

  • Excel on Windows, Mac, or Excel for the web — the functions below work in all three (menu labels can differ slightly by version, device or region)
  • Your data in a worksheet, ideally in a single column or with a clear header row
  • One or more empty columns to the right of your data for helper formulas
  • A backup copy of the file before you overwrite original values (File > Save As, or Save a Copy)

Step-by-Step

  1. Make a backup. Save a copy of the workbook first. Overwriting your source column is the risky part of this job, and there is no undo once you save and close.
  2. Find the offending cells. Click a cell that looks like it has a stray space. Look in the formula bar — a trailing space shows as a gap between the last visible character and the end of the text. If you suspect many cells, select your range and use Home > Find & Select > Find, type a space in "Find what", and use Find All to see whether any cell contains one.
  3. Insert a helper column. Click the column header to the right of your data, right-click, and choose Insert to add a blank column. Give it a header such as "Clean".
  4. Enter the TRIM formula. In the first data row of the helper column, type =TRIM(A2) (replace A2 with the reference to your first cell). Press Enter. The result should show the text with no leading or trailing spaces.
  5. Fill the formula down. Double-click the small square at the bottom-right corner of the cell (the fill handle) to copy the formula to the bottom of the adjacent data, or drag it down manually.
  6. Spot-check the results. Click a few cleaned cells and compare them in the formula bar with the originals. Confirm that internal spaces between words still read naturally — TRIM collapses double spaces to single ones, which is usually what you want but can remove intentional spacing used for alignment.
  7. Copy the cleaned values. Select the helper column, press Ctrl+C (Cmd+C on Mac).
  8. Paste over the originals as values. Select the top cell of your original column, then use Home > Paste > Paste Values (or right-click > Paste Special > Values). This replaces the text with the cleaned text and prevents the pasted cells from carrying formulas.
  9. Delete the helper column. Right-click the column header and choose Delete so the sheet is tidy.
  10. Repeat for other columns if needed. Repeat the process for each column, or write a formula that references each column in turn.

If you also have non-breaking spaces: use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")) instead. This replaces each non-breaking space with a normal space and then trims. On Excel for the web the same formula works, and you can nest further substitutions if the text also contains tabs: =TRIM(SUBSTITUTE(SUBSTITUTE(A2,CHAR(160)," "),CHAR(9)," ")).

If you prefer not to use formulas: select the range and use Home > Find & Select > Replace. Put a single space in "Find what" and leave "Replace with" blank, then click Replace All. This removes every space in the selection, including the ones between words, so it only works safely when the text has no internal spaces (single words, codes or IDs). For text with normal words, use TRIM.

Common Mistakes

  • Pasting plain (not as values). A normal paste brings the formula across and can point at the wrong cells, leaving errors or #REF! values. Always use Paste Special > Values.
  • Assuming TRIM catches everything. TRIM leaves non-breaking spaces and some other whitespace characters untouched. If CLEAN or TRIM seems not to work, check for CHAR(160) as above.
  • Using Find & Replace > Replace All on text with internal spaces. It strips the spaces between words, turning "New York" into "NewYork". There is no undo once you save.
  • Overwriting the original before verifying. Check results first or keep a backup, because the original values are gone after the paste.
  • Ignoring numbers stored as text. TRIM returns text. If a column of numbers has trailing spaces, the result may look like text and won't sum. Convert with Value or by multiplying by 1 where appropriate.

Tips

  • Test the formula on one cell before filling down a whole column.
  • If you need to keep both the original and cleaned version, skip the overwrite step and keep the helper column, renaming it so its purpose is clear.
  • The CLEAN function removes most non-printable characters; combining =TRIM(CLEAN(A2)) handles many messy imports, though CLEAN does not remove CHAR(160).
  • For data imported from another system, apply the trim before running lookups, so match formulas don't fail silently.
  • Save the file after the paste, then spot-check the original column once more from the formula bar.

Troubleshooting

  • The formula shows the text, but it still isn't matching in VLOOKUP. The other table may contain non-breaking spaces or different characters. Trim both sides with the SUBSTITUTE version.
  • TRIM returns #NAME?. Check the spelling and the function name; a typo or a missing equals sign causes this.
  • TRIM returns #VALUE!. The referenced cell may contain an error or a value of an incompatible type; check the source cell.
  • Copied cells came across as formulas. You used a normal paste. Redo it with Paste Special > Values.
  • Numbers stopped summing after cleanup. The trimmed values are now text. Convert them back to numbers (select the range and look for the warning marker with "Convert to Number", or use Value).
  • Nothing appears to change. The cell may have a non-breaking space; try the CHAR(160) formula.
  • The column is locked or the sheet is protected. Unprotect the sheet first (Review > Unprotect Sheet) if you have the password.

Frequently Asked Questions

Does TRIM remove spaces between words?

No, it leaves single spaces between words alone. It removes leading and trailing spaces and reduces repeated internal spaces to one, but a standard single space between words stays.

Why does TRIM not remove my spaces?

Most likely they are non-breaking spaces (CHAR(160)), which TRIM ignores. Use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).

Can I trim an entire column at once?

Yes. Put the formula beside the column, fill it down, then copy and paste it over the original with Paste Special > Values.

Is there a non-formula way?

Find & Replace with a space in the search box works for words without internal spaces. For normal sentences, formulas are safer because Replace All removes every space.

Does this work in Excel for the web and on Mac?

Yes, TRIM, SUBSTITUTE, CLEAN and Paste Special > Values all exist in Excel for the web and on Mac, though menu wording can differ slightly between versions and regions.

Can I run this on several columns at once?

You can copy the formula across several helper columns and reference each source column in turn, then paste each cleaned column back over its original.