To trim spaces in Excel, use the TRIM function: in an empty cell, type =TRIM(A1) where A1 holds the text, press Enter, then copy the result and paste it back as values over the original. TRIM removes leading and trailing spaces and collapses multiple spaces between words into one. For a one-off fix, Find & Replace (Ctrl+H) can delete a specific character, but TRIM is safer because it leaves single spaces between words intact. The steps below cover both methods, plus how to handle non-breaking spaces that TRIM cannot see.

What You'll Need

  • Excel for Windows, Mac, or the web (the function and menu labels are essentially the same; minor wording differences exist by version and region)
  • A worksheet containing the text you want to clean
  • An empty column next to your data so the original values stay intact while you work

Step-by-Step

  1. Make a working copy. Select the column with the messy text, right-click the column header, and choose Copy. Right-click an empty column header nearby and choose Paste. Working on a copy means you can compare results and undo safely.
  2. Pick an empty cell beside the first value. If your text starts in B2, click C2. This is where the cleaned version will appear.
  3. Enter the TRIM formula. Type =TRIM(B2) and press Enter. The cell now shows the text with leading and trailing spaces removed and internal runs of spaces reduced to one.
  4. Fill the formula down. Click the small square at the bottom-right corner of C2 (the fill handle) and drag down to the last row, or double-click the fill handle to fill automatically to the end of the adjacent data. Every row now has a cleaned version.
  5. Check a few results. Compare the original and cleaned cells side by side. Look for rows where the visible text did not change, which usually means the problem is a non-breaking space rather than a regular space (see Troubleshooting).
  6. Convert formulas to values. Select the cleaned column, press Ctrl+C (Cmd+C on Mac), then right-click the same selection and choose Paste Special > Values. The formulas are replaced by plain text, so they no longer depend on the original column.
  7. Replace the original data. Copy the cleaned values, select the first cell of the original column, and use Paste Special > Values again. Delete the helper column when you are satisfied.
  8. For a quick one-off removal of all spaces, select the range, press Ctrl+H, type a single space in Find what, leave Replace with empty, and click Replace All. This removes every space, including the ones between words, so use it only when you want words joined together (for example, part numbers).

Common Mistakes

  • Pasting the formula instead of the value. If you copy the TRIM cell and paste normally over the original, the formula references itself or the wrong cell and returns errors or zeros. Always use Paste Special > Values.
  • Assuming TRIM removes every kind of space. TRIM handles the standard space character (code 32) only. Non-breaking spaces (code 160), common in text copied from websites or PDFs, survive TRIM and keep the cell looking padded.
  • Using Find & Replace with a space when you meant to tidy word spacing. Replace All with a space deletes the spaces between words too, turning "John Smith" into "JohnSmith".
  • Trimming numbers stored as text. TRIM returns text, so a cleaned number may still be left-aligned and unusable in calculations. Wrap it: =VALUE(TRIM(A1)) converts the result back to a number.
  • Forgetting trailing spaces break lookups. VLOOKUP, XLOOKUP, COUNTIF, and matching in Power Query treat "Apple" and "Apple " as different values. Clean both the lookup value and the lookup column.

Tips

  • To clean a whole column in one formula without a helper column, use =TRIM(A1) in the first cell of a new column and fill down, then Paste Special > Values over the original.
  • In Excel for Microsoft 365, dynamic arrays let you enter =TRIM(A2:A100) in one cell and spill the results down automatically; you still need to paste as values before deleting the source.
  • Combine TRIM with CLEAN to strip non-printing characters as well: =TRIM(CLEAN(A1)). CLEAN removes control characters but not non-breaking spaces.
  • For recurring imports, clean the data in Power Query (Transform > Format > Trim) so every refresh applies the same rule automatically.
  • Trim before you sort, filter, or build PivotTables; stray spaces create duplicate categories that look identical on screen.
  • Keep a backup of the original column until you have spot-checked the cleaned data, especially if the sheet feeds reports or dashboards.

Troubleshooting

The cell still looks padded after TRIM. The culprit is usually a non-breaking space. Test it with =CODE(RIGHT(A1,1)); if the result is 160, that is a non-breaking space. Remove it with =TRIM(SUBSTITUTE(A1,CHAR(160)," ")) or select the range and use Find & Replace, entering the non-breaking space in Find what by pressing Alt+0160 on the numeric keypad (Windows) or Option+Space (Mac), and replacing it with a normal space before running TRIM.

TRIM returns #VALUE!. The referenced cell probably contains an error value or the formula points at a merged cell. Check the source cell and unmerge if needed.

The cleaned numbers will not calculate. TRIM outputs text. Wrap the formula in VALUE or multiply by 1, for example =TRIM(A1)*1, and format the result as a number.

Paste Special > Values is greyed out. You may have copied a cell in edit mode or copied from a protected sheet. Press Esc, reselect the cell, copy again, and confirm the sheet is not protected.

You overwrote the original by mistake. Press Ctrl+Z immediately. If you have already saved and closed, check whether the file is stored in OneDrive or SharePoint, where version history can restore an earlier copy.

Frequently Asked Questions

Does TRIM remove spaces between words?

It reduces any run of multiple spaces between words to a single space, but it does not remove that single space. Use Find & Replace with a space if you need words joined with no gap at all.

Why does TRIM not remove all the spaces in my data?

TRIM only removes the standard space character. Non-breaking spaces, often pasted from web pages or PDFs, are unaffected and need SUBSTITUTE with CHAR(160) first.

Can I trim spaces without a formula?

Yes, for simple cases: select the range, press Ctrl+H, put a space in Find what, leave Replace with blank, and click Replace All. This removes every space, so it suits codes and IDs rather than names.

Does trimming spaces change the cell format?

No. TRIM changes the text content only. Number formats, colours, and borders stay as they are, but the result is text, so numeric formatting may need reapplying after you convert to values.

Will TRIM work on text imported from another system?

It works on standard spaces. If the import brings in non-breaking spaces or control characters, combine TRIM with CLEAN and SUBSTITUTE, or clean the data in Power Query before loading it into the sheet.

Can I trim spaces across an entire workbook at once?

Not with a single built-in command. Apply TRIM column by column, or use Power Query to clean each table as it loads. Macros can loop through sheets, but test on a copy first because they overwrite data.