To remove spaces in Excel, use the TRIM function: in an empty column type =TRIM(A2), where A2 holds the messy text, press Enter, and fill the formula down. TRIM removes leading, trailing and repeated spaces between words, leaving single spaces where they belong. If you need to delete every space, including the ones between words, use =SUBSTITUTE(A2," ","") or Find & Replace instead. Copy the cleaned results and paste them back as values over the originals when done.

What You'll Need

  • Excel on Windows, Mac, or Excel for the web. The functions and shortcuts below work in all three; menu labels can differ slightly by version, device and region.
  • A spreadsheet with the text you want to clean, plus at least one empty column beside it for the formula results.
  • A backup copy if the data matters. Cleaning is easy to undo, but a duplicate file removes any risk.

Step-by-Step

  1. Look at the data first. Click a cell containing a stray space and check the formula bar. Spaces at the start or end are invisible in the cell itself, so the formula bar is where you confirm the problem. Also check whether values are stored as text (often left-aligned) rather than numbers.
  2. Add a helper column. Click the column header to the right of your data, right-click, and choose Insert so you get a clean empty column. Putting formulas here means your original data stays untouched until you are happy with the result.
  3. Enter the TRIM formula. In the first empty cell of the helper column, type =TRIM(A2), replacing A2 with the first cell that has the space problem. Press Enter. You should see the text with extra spaces gone.
  4. Check the result before filling down. Click the new cell, confirm the text looks right, then check a couple of tricky rows individually, for example a blank cell or a very long entry.
  5. Fill the formula down the column. Select the cell, grab the small square handle at its bottom-right corner, and drag down to the last row. Alternatively, double-click the handle and Excel fills to the end of the adjacent column. Copy and paste works too.
  6. Choose the right formula for your goal. Use =TRIM(A2) when you want normal single spaces kept between words. Use =SUBSTITUTE(A2," ","") when you want all spaces removed, which is usually right for codes, product IDs and postcodes. If you need both, combine them: =SUBSTITUTE(TRIM(A2)," ","").
  7. Handle non-breaking spaces. TRIM only removes the standard space character. Text pasted from web pages or other systems often contains a non-breaking space (character code 160), which TRIM ignores. Clean it with =SUBSTITUTE(TRIM(A2),CHAR(160)," ") first, then trim again, or nest it: =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).
  8. Replace the original data. Select the whole helper column, press Ctrl+C (Cmd+C on Mac), then right-click the first cell of the original column and choose Paste Special. In the Paste Special dialog, pick Values and click OK. This overwrites the old text with the cleaned result and leaves no formulas behind.
  9. Delete the helper column. Right-click its header and choose Delete. Save the workbook.

If your only problem is spaces at the edges of a few cells, you can skip formulas entirely: select the range, open the Home tab, and use Find & Replace (Ctrl+H, Cmd+H on Mac) with a single space in Find what and nothing in Replace with. Replace All removes every space in the selection, so use this only when you want spaces deleted, not normalised.

Common Mistakes

  • Replacing the original with formulas. Pasting the helper column normally leaves links to the source cells. Always use Paste Special > Values, or deleting the helper column will break the results.
  • Using Find & Replace for word spacing. Replace All deletes the spaces between words too, turning "John Smith" into "JohnSmith". Use TRIM for that job.
  • Forgetting non-breaking spaces. When TRIM appears to do nothing, a pasted non-breaking space is usually the culprit. Convert it with SUBSTITUTE and CHAR(160).
  • Cleaning numbers that should stay numbers. If TRIM is applied to a column of numeric values, the output is text. Convert back with Paste Special > Values and then, if needed, the Text to Columns wizard or multiplying by 1.
  • Trimming lookup keys only on one side. If you trim the lookup value but not the table it searches, VLOOKUP and XLOOKUP will still fail. Clean both.
  • Ignoring the fill range. Dragging the formula a row too far leaves blank rows with formulas that later look like real data.

Tips

  • Clean data at paste time, before you build reports on top of it. Fixing a key column later means rebuilding every lookup that depends on it.
  • Convert your range to an Excel Table (Ctrl+T) first. A new formula column then fills every row automatically and expands when you add data.
  • Use Flash Fill as a quick alternative for one-off jobs: type the cleaned version beside the first value, press Enter, then press Ctrl+E. It is fast but is not a formula, so it will not update when the source changes.
  • Add a check column with =LEN(A2)=LEN(TRIM(A2)). It returns TRUE for clean cells, so you can filter for FALSE and confirm nothing was missed.
  • Apply TRIM to concatenated text as well. If you build labels with & and get double spaces or leading gaps, wrap the result in TRIM.
  • Keep a copy of the original column until your checks pass. Undo history is limited, and a second copy costs nothing.

Troubleshooting

  • TRIM changed nothing. The text may be stored as a number formatted with spaces, or it may contain non-breaking spaces. Check the formula bar, then try the CHAR(160) substitution.
  • The cell shows a formula instead of a result. The cell is probably formatted as Text. Change the format to General, then re-enter the formula.
  • You see #VALUE!. One of the referenced cells contains an error, or the argument is malformed. Click the cell, check the formula in the formula bar, and verify each referenced cell.
  • Lookups still fail after trimming. One side is still dirty, or the values differ in case or type. Trim both ranges and confirm the data types match.
  • You pasted values and lost formulas elsewhere. Press Ctrl+Z straight away. If you have saved, restore the previous version from the file's version history rather than retyping.
  • The result is text, not a number. Use Paste Special > Multiply by 1, or the Text to Columns wizard with the General format, to convert back.

Frequently Asked Questions

What is the difference between TRIM and SUBSTITUTE?

TRIM removes leading and trailing spaces and collapses repeated spaces between words to one. SUBSTITUTE replaces a specific character, so SUBSTITUTE(text," ","") deletes all spaces, including those between words. TRIM preserves readable text; SUBSTITUTE suits codes and identifiers.

Does TRIM remove line breaks and tabs?

No. TRIM only handles the standard space character. Line breaks and tabs need CLEAN: =TRIM(CLEAN(A2)) removes non-printing characters first, then trims the result.

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

Pasted text often contains non-breaking spaces (character code 160), which TRIM does not recognise. Replace them with ordinary spaces using SUBSTITUTE and CHAR(160), then trim.

Can I remove spaces without adding a column?

Yes. Select the range and use Find & Replace with a space in Find what and an empty Replace with. That deletes all spaces, so it is only suitable when you want no spaces at all.

Does cleaning spaces in Excel change the original file if I use a formula?

No. Formulas in a helper column leave the source cells untouched. The originals change only when you paste the results back as values or overwrite them manually, so keep a backup until you have checked the output.

Will removing spaces break my VLOOKUP formulas?

It can, if you clean one column but not the table it searches. Clean both the lookup value and the lookup column so the entries match exactly, then the formulas will work as before.