You can strip spaces in Excel with a formula, a menu command, or a quick find-and-replace, and the right choice depends on whether you want to clean the data in place or keep the original intact. The fastest all-purpose method is the TRIM function: put =TRIM(A2) in an empty column, fill it down, then copy the results and paste them back as values over the originals. TRIM removes leading and trailing spaces and collapses runs of multiple spaces between words down to one. If you only need to remove every space, including the single ones between words, use SUBSTITUTE or Find & Replace instead.
Before you start, note that Excel menus and labels differ slightly between the desktop app, Excel for the web, and the mobile apps, and between Windows and Mac. The steps below use the desktop app on Windows, with Mac differences called out where they matter. Nothing here deletes data unless you paste over it, so work on a copy if the sheet matters.
What You'll Need
- Excel for Windows, Mac, or Excel for the web (the formulas work in all of them).
- A spreadsheet with the text you want to clean, ideally with one column of names, addresses, or codes.
- One empty column to the right of your data for the cleaned results.
- Optional: a backup copy of the file, in case a paste lands in the wrong place.
Step-by-Step
- Identify the problem spaces. Click a cell and look at the formula bar. If you see spaces before or after the text, those are leading or trailing spaces. If you see double spaces between words, those are internal runs. This tells you which method you need.
- Insert a helper column. Right-click the column letter to the right of your data and choose Insert. Give it a header such as Clean.
- Enter the TRIM formula. In the first data row of the helper column, type
=TRIM(A2), replacing A2 with the first cell of your messy data. Press Enter. - Fill the formula down. Select the cell, then double-click the small square at its bottom-right corner (the fill handle). Excel fills the formula to the last row of adjacent data. Alternatively, drag the handle down or copy the cell and paste it into the range below.
- Check the results. Compare a few rows side by side. The cleaned column should show the same text with no leading or trailing spaces and single spaces between words.
- Convert formulas to values. Select the whole helper column, press Ctrl+C (Cmd+C on Mac), then right-click the same selection and choose Paste Special > Values. This replaces the formulas with plain text so they no longer depend on the original cells.
- Replace the originals. With the cleaned values still selected, copy them, click the first cell of the original column, and use Paste Special > Values again. Delete the helper column when you are satisfied.
- For a full space removal, use SUBSTITUTE. If you want to delete every space, not just tidy them, use
=SUBSTITUTE(A2," ",""). This turns "AB 12 CD" into "AB12CD", which is useful for postcodes, product codes, and phone numbers. Follow the same fill, convert-to-values, and paste-back steps. - For a one-off fix, use Find & Replace. Select the column, press Ctrl+H (Cmd+H on Mac), type a single space in Find what, leave Replace with empty, and click Replace All. This removes every space in the selection, including the ones between words, so use it only when that is what you want. It cannot remove only leading or trailing spaces.
- Handle non-breaking spaces if TRIM fails. Text pasted from web pages often contains a non-breaking space (character code 160), which TRIM does not remove. Use
=TRIM(SUBSTITUTE(A2,CHAR(160)," "))to convert those to normal spaces first, then trim.
Common Mistakes
Pasting formulas over the originals. If you copy the helper column and paste normally, you paste formulas that still point at the original cells, and the values can shift or turn into errors. Always use Paste Special > Values.
Using Find & Replace when you only wanted a tidy-up. Replace All with a space in the Find box deletes the spaces between first and last names too. Use TRIM for tidying and SUBSTITUTE or Replace All only for genuine full removal.
Expecting TRIM to fix non-breaking spaces. It does not. The CHAR(160) wrapper above is the fix.
Forgetting the fill handle only fills to the end of adjacent data. If there are blank rows in the source column, the double-click fill stops early. Drag manually or copy and paste the formula instead.
Cleaning a column that feeds a lookup or a pivot. If other sheets reference the original text, changing it can break matches. Clean the source first, then refresh the lookup or pivot.
Tips
Use TRIM on imported CSV files as a habit; exported data from other systems very often carries trailing spaces that make VLOOKUP and XLOOKUP fail silently. A quick test is =LEN(A2) next to =LEN(TRIM(A2)): if the numbers differ, spaces are present.
If you clean the same data regularly, consider Power Query: import the table, apply a Trim transform to the column, and load it back. The steps are recorded, so next month's file needs only a refresh. The exact ribbon labels vary by version, so look for the Transform tab and a Trim option in the Text Column group.
To remove only leading or trailing spaces without touching internal ones, TRIM is still the right tool, since it collapses internal runs to one space rather than deleting them. If you must keep double spaces inside the text, use a formula with LEFT, RIGHT, and LEN, or clean the data in a text editor before importing.
Troubleshooting
The formula shows as text. The cell is probably formatted as Text. Select the column, open the Number Format dropdown on the Home tab, and choose General, then re-enter the formula.
TRIM leaves spaces behind. They are likely non-breaking spaces. Apply the CHAR(160) substitution shown above.
Paste Special > Values is greyed out. You may be in cell edit mode or have a protected sheet. Press Esc, then check Review > Unprotect Sheet if the workbook is protected.
The cleaned column shows #REF! or wrong values after pasting. Undo with Ctrl+Z immediately, then repeat the copy and choose Paste Special > Values while the source range is still selected.
Spaces reappear after reopening the file. Something is re-importing the data, such as a Power Query refresh or a linked table. Clean the source or add the trim step to the query itself.
Frequently Asked Questions
Does TRIM remove all spaces?
No. It removes leading and trailing spaces and reduces multiple internal spaces to one. Use SUBSTITUTE or Find & Replace to remove every space.
Can I strip spaces without a formula?
Yes. Find & Replace with a space in the Find box and nothing in Replace removes all spaces in the selected cells. It cannot target only leading or trailing spaces.
Why does TRIM not work on my pasted data?
Web pages often use non-breaking spaces. Wrap TRIM around SUBSTITUTE with CHAR(160) to convert them first.
Will this work in Excel for the web?
Yes. TRIM, SUBSTITUTE, and Paste Special > Values all work there, though the right-click menu wording may differ slightly.
Can I clean a whole sheet at once?
Not with a single built-in command. Apply the formula per column, or use Power Query to trim all text columns in one transform step.