Operelio

How to remove spaces in Excel

To remove extra spaces in Excel, use =TRIM(A2). It deletes leading and trailing spaces and turns double spaces between words into one. To remove every space, use Find and Replace: a space in Find what, nothing in Replace with.

By Operelio team · Updated November 7, 2026 · 9 min read

On this page11 sections
  1. 1Three ways to do it
  2. 2How to remove extra, leading and trailing spaces with TRIM
  3. 3How to remove only leading or only trailing spaces
  4. 4How to remove all spaces with Find and Replace
  5. 5How to remove spaces between numbers
  6. 6How to remove spaces with SUBSTITUTE
  7. 7Find the character TRIM won't remove: non-breaking spaces and line breaks
  8. 8How to remove spaces in Google Sheets
  9. 9Why spaces matter before an import
  10. 10Remove spaces across a whole file
  11. 11Frequently asked questions

Three ways to do it

Which one depends on whether the spaces between words should stay.

MethodWhat it removesChanges your data
TRIM functionSpaces at the start and end, and repeated spaces between words. One space between words stays.No, it writes a cleaned copy in a new column
Find and ReplaceEvery space in the cells you select, including the ones between wordsYes, in place
SUBSTITUTE functionEvery space, or any one character you name, such as a non-breaking spaceNo, it writes a cleaned copy in a new column

How to remove extra, leading and trailing spaces with TRIM

TRIM is the one to use on names, company names and emails, where a stray space at the end is the problem and the spaces between words are meant to be there. It removes the spaces before the text and after it, and leaves one space between words. The example cleans names in column A.

  1. Add a helper column

    Right-click the column letter next to your data and choose Insert, so you have an empty column B.

  2. Type the formula

    In B2, type =TRIM(A2) and press Enter. A name typed with two spaces before it, three between the words and one after becomes "Jane Cole".

  3. Copy it down

    Click B2 and double-click the small square at its bottom right. Excel fills the formula down as far as column A goes.

  4. Replace the originals with the results

    Select the results in column B and copy them. Right-click A2 and choose Paste Special > Values, then delete column B. Pasting values matters: if you delete column B while it still holds formulas, the cleaned text goes with it.

How to remove only leading or only trailing spaces

TRIM does three things at once: it removes the spaces at the start, the spaces at the end, and turns a run of spaces between words into one. When the spacing inside the text has to stay as it is, such as a code or an address with two spaces in it on purpose, use one of these formulas instead. Like TRIM, they count only the ordinary space as a space.

The leading formula finds the first character that isn't a space and keeps everything from there. The trailing one finds the last: RIGHT(TRIM(A2), 1) is the last character that isn't a space, SUBSTITUTE marks its last appearance in A2 with CHAR(127), a character that doesn't print and isn't in ordinary text, and LEFT keeps everything up to the mark. It works when the same letter appears earlier in the text too. A cell of nothing but spaces comes back empty from both.

Every function in them is in Excel 2016 and later, on Windows and Mac. Copy the formula down and paste the results over the originals with Paste Special > Values, as with TRIM above.

To removeFormula in B2What stays
Leading spaces only=IF(TRIM(A2)="", "", MID(A2, FIND(LEFT(TRIM(A2), 1), A2), LEN(A2)))The spaces between words and at the end
Trailing spaces only=IF(TRIM(A2)="", "", LEFT(A2, FIND(CHAR(127), SUBSTITUTE(A2, RIGHT(TRIM(A2), 1), CHAR(127), LEN(A2)-LEN(SUBSTITUTE(A2, RIGHT(TRIM(A2), 1), ""))))))The spaces at the start and between words

How to remove all spaces with Find and Replace

Find and Replace removes every space, including the ones between words, so use it on values that should have none: phone numbers, IDs, ZIP codes, or emails that were typed with a space in them. It changes the cells in place.

Phone numbers need care. A cell left with only digits turns into a number, so 0131 496 0509 becomes 1314960509 and the leading 0 is gone. For phone numbers, use SUBSTITUTE, below, which keeps the result as text.

  1. Select the cells

    Select the column or range to clean. With one cell selected, Excel searches the whole sheet, so select the range to keep it to the column you mean.

  2. Open Find and Replace

    Press Ctrl+H. On a Mac, press Control+H or Cmd+Shift+H, or go to Home > Find & Select > Replace. Cmd+H on its own hides Excel.

  3. Find a space, replace with nothing

    Click in Find what and press the space bar once. Leave Replace with empty.

  4. Click Replace All

    Excel says how many replacements it made, one for each space, not each cell. If the number looks wrong, press Ctrl+Z (Cmd+Z on a Mac) to undo.

    Excel for Mac after Replace All on the Phone column: a message says "All finished. We made 144 replacements." and the numbers in column C now read 1314960509 and 7700900373, with no spaces and no leading 0.
    On a Mac. 144 spaces went, and every phone number lost its leading 0.

How to remove spaces between numbers

Exports and typed figures often have spaces inside numbers, such as 1 250 000 or 3 100 000. Take the spaces out and Excel can read the figure as a number again.

Don't do this to phone numbers. A phone number that becomes a number loses its leading 0 and any + sign, so 0131 496 0509 becomes 1314960509. Keep phone numbers as text with =SUBSTITUTE(A2, " ", ""), below, and see how to format phone numbers in Excel to give a whole list one format.

  1. Remove the spaces with Find and Replace

    Select the column, press Ctrl+H (Control+H on a Mac), type a space in Find what, leave Replace with empty and click Replace All. Excel turns a cell left with only digits into a number, as the phone numbers in the picture above show.

  2. Convert any that stay as text

    A small green triangle in the top left corner of a cell means its number is stored as text. Select those cells, select the error indicator next to them and choose Convert to Number.

  3. Or use a formula

    In a new column, =VALUE(SUBSTITUTE(A2, " ", "")) removes the spaces and returns a number: 1 250 000 becomes 1250000. Copy it down, then paste the results over the originals with Paste Special > Values.

How to remove spaces with SUBSTITUTE

SUBSTITUTE replaces one piece of text with another inside a cell. With an empty replacement it removes it: =SUBSTITUTE(A2, " ", "") returns A2 with every space taken out, and leaves A2 itself as it is.

This is the formula for phone numbers and IDs, because the result stays text: 415 555 0123 becomes 4155550123, and a leading 0 or a + stays. For figures that should become numbers, see how to remove spaces between numbers.

To remove only the first space, or any other single one, SUBSTITUTE takes a fourth argument, the occurrence: =SUBSTITUTE(A2, " ", "", 1) removes the first space and keeps the rest.

Find the character TRIM won't remove: non-breaking spaces and line breaks

TRIM only removes the ordinary space, character 32. Text copied from a web page, a PDF or some exports often has non-breaking spaces instead, character 160. They look the same on screen and TRIM leaves them alone. A line break inside a cell is another character, number 10. Find and Replace with a typed space misses both.

To see which one you have, ask Excel for the character's code. =UNICODE(RIGHT(A2, 1)) gives the code of the last character, =UNICODE(A2) the first, and =UNICODE(MID(A2, 5, 1)) the fifth. Use UNICODE rather than CODE: CODE answers in your computer's character set, so on a Mac it gives a different number for a non-breaking space. To count the ordinary spaces in a cell, use =LEN(A2)-LEN(SUBSTITUTE(A2, " ", "")).

For a non-breaking space, turn it into an ordinary space, then trim: =TRIM(SUBSTITUTE(A2, UNICHAR(160), " ")). Use UNICHAR, not CHAR: in Excel for Mac, CHAR(160) is a different character, so the formula changes nothing there. UNICHAR(160) is the non-breaking space on Windows and Mac. To remove them in place with Find and Replace on Windows, click in Find what, hold Alt and type 0160 on the number keypad, type one ordinary space in Replace with, then Replace All. Replacing them with nothing joins the words on either side, so Halden Ltd becomes HaldenLtd. Then use TRIM, as above, to clear the spaces left at the start and end.

For a line break, CLEAN removes it along with the other characters that don't print, but it leaves nothing in its place, so Brightlane and Inc on two lines become BrightlaneInc. Swap line breaks for a space first: =TRIM(CLEAN(SUBSTITUTE(SUBSTITUTE(A2, UNICHAR(160), " "), CHAR(10), " "))) handles all three. CLEAN doesn't remove non-breaking spaces on its own, which is why the first SUBSTITUTE stays in the formula.

CodeWhat it isFormula that removes it
32An ordinary space=TRIM(A2) for the extra ones, =SUBSTITUTE(A2, " ", "") for all of them
160A non-breaking space, common in text from web pages=TRIM(SUBSTITUTE(A2, UNICHAR(160), " "))
10A line break inside the cell=TRIM(SUBSTITUTE(A2, CHAR(10), " "))
0 to 31Other characters that don't print=CLEAN(SUBSTITUTE(A2, CHAR(10), " ")), which keeps a space where a line break was

How to remove spaces in Google Sheets

TRIM and SUBSTITUTE work the same way in Google Sheets: =TRIM(A2) for extra spaces, =SUBSTITUTE(A2, " ", "") for all of them.

If the data came in through File > Import with Convert text to numbers, dates, and formulas left on, the default, Sheets has already removed the spaces at the start and end of each cell. Double spaces between words and non-breaking spaces stay.

Sheets also has a menu command that trims in place, with no helper column. Select the cells and go to Data > Data cleanup > Trim whitespace. It removes leading, trailing and repeated spaces. It leaves non-breaking spaces, so for text copied from the web, use =TRIM(SUBSTITUTE(A2, UNICHAR(160), " ")) as in Excel. On a UK account the menu reads Data clean-up.

To remove every space in place, use Edit > Find and replace (Ctrl+H, or Cmd+Shift+H on a Mac): a space in Find, nothing in Replace with, then Replace all. As in Excel, a phone number left with only digits turns into a number and loses its leading 0.

Google Sheets' message after Data cleanup, Trim whitespace: Trimmed whitespace from 9 selected cells.
Trim whitespace on the Name and Email columns.

Why spaces matter before an import

A space you can't see makes two values different. jane@example.com and the same address with a space at the end are two values to Excel, so Remove Duplicates keeps both rows, and a VLOOKUP on that email returns #N/A. Clean the spaces first, then remove duplicates or run the lookup.

The same goes for a CRM import. Some importers trim spaces and some don't, so clean them in the file and the result doesn't depend on which one you use.

Remove spaces across a whole file

Operelio's Find & Replace works on a CSV or Excel file without opening it. In the first rule, turn on Advanced patterns, and use ^\s+|\s+$ as the find, with the box after Then: Replace left empty: it removes spaces at the start and end of every cell, non-breaking spaces included, and leaves the spaces between words as they are. \s+ removes every space. Set Runs on to the columns you mean, check the preview, and run it. Your original file is never changed.

If the file is going into HubSpot, Salesforce or Pipedrive, the CRM Formatter also trims emails and strips spaces from phone numbers on the way in.

Operelio's Find & Replace with Runs on set to Entire file and Rule 1 finding ^\s+|\s+$ with Advanced patterns on and the replace box empty. It reads 15 matches and 7 rows change, and the preview shades the changed cells: Jane Cole, her email and Harborline Ltd in row 2, and Tom Hale's email, company and phone in row 3.
A sample file with made-up names: 15 cells in 7 of its 8 rows had spaces at the start or end, some of them non-breaking. Tom Hale's name isn't shaded: its only extra space is the one between his names, which stays.

Frequently asked questions

How do I remove blank spaces in Excel?

For spaces inside cells, use TRIM to remove the extra ones or Find and Replace to remove them all. For blank cells, select the range, go to Home > Find & Select > Go To Special, choose Blanks and click OK, then Home > Delete > Delete Sheet Rows. That deletes every row with a blank cell in the selection, so select only the column that should never be empty.

How do I remove spaces between numbers in Excel?

Use Find and Replace with a space in Find what and nothing in Replace with, then Convert to Number on any cell that still has a green triangle. Or use =VALUE(SUBSTITUTE(A2, " ", "")) in a new column. Keep phone numbers as text with =SUBSTITUTE(A2, " ", "") so a leading 0 or + stays.

Is there a shortcut to remove spaces in Excel?

Ctrl+H opens Find and Replace (Control+H or Cmd+Shift+H on a Mac). Put a space in Find what, leave Replace with empty and click Replace All. In Power Query, select the column and go to Transform > Format > Trim, which removes the spaces at the start and end of each value and keeps the ones between words.

How do I remove spaces in Excel without a formula?

Find and Replace removes every space in place. Power Query's Transform > Format > Trim removes the spaces at the start and end of each value. To clean a whole CSV or Excel file without opening it, Operelio's Find & Replace removes the spaces at the start and end of every cell in the columns you pick.

Next in Spreadsheet cleanup How to use Text to Columns in Excel and Google SheetsSplit one column into several with Text to Columns in Excel, or Split text to columns in Google Sheets. Delimiters, fixed width, and joining text back.9 min read

Try it on your own file

Upload a file and run your first tool on it. Free, no credit card required.