You can trim spaces in an Excel column with the built-in TRIM function: put =TRIM(A2) in a helper column beside your data, fill it down, then copy the results and paste them back over the original column as values. TRIM removes leading and trailing spaces plus any doubled spaces between words, leaving single spaces. If your spaces are non-breaking characters (common in text pasted from websites or exported from other systems), TRIM may fail and you should use =SUBSTITUTE(A2,CHAR(160),"") instead. Labels and menu positions vary slightly by Excel version and by platform (Windows, Mac, Excel for the web), so the exact wording you see may differ a little from the steps below.
What You'll Need
- Excel (Microsoft 365, Excel 2019 or later, Excel for Mac, or Excel for the web all work). The steps are written for the desktop app; Excel for the web has the same functions but a slightly different ribbon layout.
- Your data already in a worksheet, ideally in a proper column with a header row.
- A spare empty column next to your data to hold the helper formula, plus the ability to sort or filter if you want to find problem cells first.
- A backup copy of the sheet (or a quick Ctrl+Z / Cmd+Z ready) before you overwrite the original column, because pasting values over your source is destructive.
Step-by-Step
- Identify the column and inspect the spaces. Click a cell with a stray space and look in the formula bar. A visible gap before or after the text is a normal space. Nothing visible but the text still refuses to match elsewhere is often a non-breaking space or a line break — you will handle those separately in step 8.
- Insert a helper column. Right-click the column header letter to the right of your data and choose Insert, or simply use the next empty column. Give it a header such as Clean.
- Write the TRIM formula in the first data row. If your original values start in A2, put this in the helper cell of the same row:
=TRIM(A2). Press Enter. The result should show the same text with no leading or trailing spaces and single spaces only between words. - Fill the formula down. Hover over the small square at the bottom-right corner of the formula cell until the cursor becomes a plus, then double-click to auto-fill to the end of the adjacent data, or drag it down. You can also select the range and press Ctrl+D (Cmd+D on Mac).
- Check a few results before continuing. Look at rows where you know spaces exist. Confirm numbers have not lost anything important and true blanks are still blank (see Common Mistakes about numbers and blank cells).
- Convert the formulas to values. Select the whole helper column range (not the header), copy it with Ctrl+C (Cmd+C), then right-click and choose Paste Special, or use the Values option in the Paste dropdown. If you prefer a shortcut, use Ctrl+Alt+V on Windows or Cmd+Ctrl+V on Mac, then pick Values. This step is what stops the formulas breaking when you delete the original column.
- Replace the original column. With the clean values still copied, or after re-copying the helper column, select the first cell of your original data column and paste. Now the original column holds clean, static text.
- Delete the helper column. Right-click its header and choose Delete. Your data now has trimmed text in the original position, so any formulas, charts or references pointing at that column keep working.
- If you have no free space or want it done in place, use Text to Columns as an alternative. Select the column, go to the Data tab, choose Text to Columns, click Next twice to reach step 3 of the wizard, and choose Next again. Then choose Delimited with a delimiter that does not appear in your data (a rare character such as |), and finish. This path removes leading and trailing spaces, though it can behave unpredictably with some formatting and is best on a copy first.
- Handle non-breaking spaces and line breaks. If TRIM gives no change, try
=SUBSTITUTE(A2,CHAR(160),"")to strip non-breaking spaces, or=SUBSTITUTE(A2,CHAR(10)," ")to replace line breaks with a normal space. You can nest these inside TRIM:=TRIM(SUBSTITUTE(A2,CHAR(160)," ")). Copy and paste as values using the same method as steps 6–8. - Verify the clean-up. Use a filter (Data tab, Filter) on the column or press Ctrl+F and search for a leading space. Also check that COUNTIF or VLOOKUP lookups that previously failed now match. If a number still will not add up, it may be stored as text — see Troubleshooting.
Common Mistakes
- Pasting the formula instead of the values. If you copy the helper cells with a normal paste, the pasted cells point at the original column. When you delete the original column, those references break and the column fills with #REF! errors. Always use Paste Special > Values.
- Assuming TRIM fixes every space. TRIM only removes the standard space character (code 32) plus a few line breaks in some cases. Non-breaking spaces (code 160) survive TRIM entirely, which is the most common reason a column still looks dirty after trimming.
- Wiping out numbers or dates. If a column is genuinely numeric with no spaces, TRIM turns the number into text. That breaks SUM, sorting and formatting. Only apply TRIM to columns that actually contain text with stray spaces.
- Losing leading zeros or codes. Applying TRIM to a column of product codes or phone numbers converts them to text and may drop formatting such as leading zeros. Check before you overwrite.
- Deleting the helper column before the paste. Do the copy, Paste Special > Values, replace source, then delete. Doing it in the wrong order loses work.
- Trim instead of cleaning the source. If the spaces come from a recurring import, fix the import step or use Power Query's Trim transform so the problem does not return next month.
Tips
- To trim an entire range in one formula with dynamic arrays, use
=TRIM(A2:A1000)in recent Excel versions and it spills down automatically. You can then wrap withIFto skip blanks:=IF(A2="","",TRIM(A2)). - Use
CLEANalongside TRIM when text was imported:=TRIM(CLEAN(A2))removes many non-printing characters as well as extra spaces. - If you only care about visible characters and want to find them fast, press Ctrl+H (Find and Replace) and search for two spaces, replacing with one. Repeat the Replace All command until it reports no matches. This does not touch leading or trailing spaces, so combine it with TRIM for a full clean-up.
- Power Query is the cleanest option for recurring imports: load the data, right-click the column header, choose Transform > Trim, then load the result back to the sheet. The step is saved and re-applied on every refresh.
- Keep a copy of the raw data on another sheet before any bulk replace. A quick duplicate sheet is far less painful than rebuilding data.
- Trim your header row separately so that column headings also match lookups and pivot labels.
Troubleshooting
- TRIM does nothing at all. The spaces are almost certainly non-breaking. Use the SUBSTITUTE with CHAR(160) approach, or wrap it:
=TRIM(SUBSTITUTE(A2,CHAR(160)," ")). - The cell still seams to contain a space but looks empty. A formula can return an empty-looking string that is not truly blank. Check with
=LEN(A2). If LEN is greater than zero, there is a hidden character; finding and removing it with SUBSTITUTE by character code is the fix. - Numbers stop summing after trimming. They are now text. Use Paste Special > Add with a zero in a spare cell, or use Value formulas, or re-enter as numbers. In newer Excel versions the error-check marker on the cell offers Convert to Number.
- You get #REF! after replacing the column. That means you pasted formulas rather than values. Undo with Ctrl+Z, repeat the copy on the helper column, choose Paste Special > Values, then retry.
- The find and replace removed the wrong characters. If your data has meaningful double spaces (for example inside addresses), replacing globally will flatten them. Undo and use TRIM only, or target specific cells.
- Merged cells give trouble. TRIM formulas behave badly across merged cells. Unmerge first, clean the data, then remerge if needed.
Frequently Asked Questions
Does TRIM remove spaces between words?
It reduces any run of multiple spaces between words to a single space, but does not remove the single space. Only leading, trailing and duplicate spaces are removed.
Can I trim several columns at once?
Yes. Write =TRIM(A2) for the first column, then copy the formula across for each column you want cleaned, and fill down. Paste Special > Values over the originals when done.
Why does my TRIM formula still show a space?
The space is probably a non-breaking space or a line break. Combine TRIM with SUBSTITUTE using CHAR(160) for non-breaking spaces and CHAR(10) for line breaks.
Does trimming change the cell's number format?
TRIM returns text, so the result is text even if the source was a number or date. Reapply the format or convert the result back to a number with Paste Special > Add if you need calculations.
Can I undo trimming?
Only if you have not saved the file. Ctrl+Z after a paste will step back, but once you save, the original column is gone. Keep a backup copy before you paste over anything.
Is there a one-click trim button?
Excel has no built-in Trim button on the ribbon. The quickest one-click style option is the Text to Columns wizard or Power Query's Trim transform; both are covered above.