When working with data in Excel, it's not uncommon to encounter cells with unwanted spaces. These spaces can cause issues with data analysis, formatting, and even data validation. Fortunately, removing spaces in Excel cells is a relatively straightforward process. In this article, we'll explore the various methods to remove spaces in Excel cells, including using formulas, functions, and shortcuts.
Understanding the Types of Spaces in Excel

Before we dive into the methods for removing spaces, it's essential to understand the types of spaces that can occur in Excel cells. There are two primary types of spaces:
- Trailing spaces: These are spaces that occur at the end of a cell's content.
- Leading spaces: These are spaces that occur at the beginning of a cell's content.
- Extra spaces: These are spaces that occur within the content of a cell.
Method 1: Using the TRIM Function

One of the most efficient ways to remove spaces in Excel cells is by using the TRIM function. The TRIM function removes all spaces from a cell, except for single spaces between words.
Syntax: TRIM(text)
Example:
Original Text | TRIM Function |
---|---|
" Hello World " | =TRIM(A1) |
Result: "Hello World"
How to Use the TRIM Function
- Select the cell where you want to remove spaces.
- Type
=TRIM(
and select the cell that contains the text with spaces. - Close the parenthesis and press Enter.
- The TRIM function will remove all spaces, except for single spaces between words.
Method 2: Using the SUBSTITUTE Function

Another way to remove spaces in Excel cells is by using the SUBSTITUTE function. The SUBSTITUTE function replaces a specified character or string with another character or string.
Syntax: SUBSTITUTE(text, old_text, new_text)
Example:
Original Text | SUBSTITUTE Function |
---|---|
" Hello World " | =SUBSTITUTE(A1," ","") |
Result: "HelloWorld"
How to Use the SUBSTITUTE Function
- Select the cell where you want to remove spaces.
- Type
=SUBSTITUTE(
and select the cell that contains the text with spaces. - Specify the old text as a space (
" "
) and the new text as an empty string (""
). - Close the parenthesis and press Enter.
- The SUBSTITUTE function will remove all spaces from the text.
Method 3: Using Find and Replace

You can also use the Find and Replace feature in Excel to remove spaces from cells.
How to Use Find and Replace
- Select the cell range that contains the text with spaces.
- Press Ctrl + H to open the Find and Replace dialog box.
- In the Find what field, type a space (
" "
) and leave the Replace with field blank. - Click Replace All to remove all spaces from the selected cells.
Method 4: Using Power Query

If you're using Excel 2010 or later, you can use Power Query to remove spaces from cells.
How to Use Power Query
- Select the cell range that contains the text with spaces.
- Go to the Data tab and click From Table/Range.
- In the Query Editor, select the column that contains the text with spaces.
- Go to the Home tab and click Transform Data.
- In the Transform Data dialog box, select the Text column and click Remove Spaces.
- Click OK to remove all spaces from the selected column.
Method 5: Using VBA Macro

You can also use a VBA macro to remove spaces from cells.
How to Use a VBA Macro
- Open the Visual Basic Editor by pressing Alt + F11.
- In the Editor, insert a new module by clicking Insert > Module.
- Paste the following code:
Sub RemoveSpaces() Range("A1").Value = Trim(Range("A1").Value) End Sub
- Replace "A1" with the cell range that contains the text with spaces.
- Run the macro by clicking Run > Run Sub/UserForm or press F5.
Gallery of Removing Spaces in Excel
Removing Spaces in Excel









Conclusion
Removing spaces in Excel cells can be a tedious task, but with the right methods, it can be done efficiently. In this article, we explored five different methods to remove spaces in Excel cells, including using the TRIM function, SUBSTITUTE function, Find and Replace, Power Query, and VBA macro. Whether you're dealing with trailing spaces, leading spaces, or extra spaces, these methods can help you remove them quickly and easily.