How to Remove White Space in Excel (6 Easy Ways)

In the sample dataset, we have placed some random employee names and their office IDs. There are many unnecessary spaces in the employee names. Let’s remove those white spaces.

Sample dataset with Employee Names with Extra spaces to show how to remove white space in Excel


Method 1 – Use the TRIM Function to Remove Extra White Spaces in Excel

  • Select cell D5 and copy the following formula:
=TRIM(C5)

Trim Function to Remove White Space in Excel

  • Press Enter to get the result.

using TRIM function to remove white spaces

  • Use the Fill Handle icon to copy the formula for the other cells.

Autofilling the data by using Fill Handle


Method 2 – Apply the Find and Replace Tool to Remove White Spaces in Excel

  • Press Ctrl + H to open the Find and Replace dialog box.
  • Press the Space key twice in the Find What bar.
  • Keep the Replace with bar empty.
  • Press Replace All.

‘Find And Replace’ Tool to Remove White Space in Excel

  • All double spaces are removed with a notification showing how many replacements were made.

‘Find And Replace’ Tool to Remove White Space in Excel

Read More: How to Remove Blank Spaces in Excel


Method 3 – Use the SUBSTITUTE Function to Remove White Spaces in Excel

In our modified dataset, there are some extra spaces between the office ID numbers.

Steps:

  • Copy this formula in cell D5:
=SUBSTITUTE(B5," ","")

SUBSTITUTE Function to Remove White Space in Excel

  • Hit Enter.

Use of SUBSTITUTE Function to Remove White Space in Excel

  • Use the AutoFill option to copy the formula to the rest of the cells.

using Fill Handle to autofill the rest of the cells


Method 4 – Combining TRIM, LEFT and LEN Functions to Remove Trailing Whitespaces.

Steps:

  • In cell D5, apply the following formula and hit the Enter.
=TRIM(LEFT(C5,LEN(C5)-1))&""

TRIM, LEFT and LEN Functions to Remove Trailing Whitespace.

  • You will get the trimmed result.

Combining TRIM, LEFT, and LEN Functions to Remove Trailing Whitespace.

  • Use the Fill Handle tool to copy the formula through the column.

using Fill Handle to autofill the rest of the cells

Breakdown of the Formula:

LEN(C5)

It will find the number of characters in Cell C5. And will return as-

{19}

LEFT(C5,LEN(C5)-1)

This function will keep the characters of Cell C5 according to the given length from the beginning of the text. It will return as-

{Alfred    Molina  }

TRIM(LEFT(C5,LEN(C5)-1))&””

Finally, the TRIM function will remove the extra spaces. Then the result will be as below-

{Alfred Molina}


Method 5 – Combining CLEAN, TRIM and SUBSTITUTE Functions to Remove All Spaces from a Cell in Excel

  • Select Cell D5 and copy the following formula into it:
=TRIM(CLEAN(SUBSTITUTE(B5," ","")))

CLEAN, TRIM, And SUBSTITUTE Functions to Remove All Spaces from a Cell in Excel

  • Press Enter.

Combining CLEAN, TRIM, And SUBSTITUTE Functions to Remove All Spaces from a Cell in Excel

  • To copy the formula to the other cells, use the Fill Handle tool.

CLEAN, TRIM, And SUBSTITUTE Functions to Remove All Spaces from a Cell in Excel

Breakdown of the Formula:

SUBSTITUTE(B5,” “,””)

This function will substitute the extra space with no space. That will return as-

{HL236744}

CLEAN(SUBSTITUTE(B5,” “,””))

The CLEAN function will then clean non printable characters if there are remain any and it will return as-

{HL236744}

TRIM(CLEAN(SUBSTITUTE(B5,” “,””)))

Finally, the TRIM function will trim extra spaces and will return as-

{HL236744}


Method 6 – Embedding Excel VBA to Remove White Spaces

  • Select the cells where you will apply VBA.
  • Right-click on the sheet title.
  • Select the View Code option from the context menu.

Excel VBA to Remove White Space

  • The Visual Basic Editor window will appear.

Opening Visual Basic Editor

  • Copy the code given below into the window.
Option Explicit
Sub Trim_Blanks()
Dim s As Range
  For Each s In Selection.Cells
    s.Value = Trim(s.Value)
  Next s
End Sub

Writing VBA Code in Editor

  • Press the Play button to run the code.

Running VBA Code by pressing Play button

  • Anew dialog box named ‘Macro’ will open. Click the Run option.

Excel VBA to Remove White Space

  • The extra white spaces are removed.

Showing Result of Removing White Space by VBA


Download Practice Book

You can download the free practice Excel template from here and exercise on your own.


Related Articles

<< Go Back To Remove Space in Excel | Data Cleaning in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Md. Sourov Hossain Mithun
Md. Sourov Hossain Mithun

Md. Sourov Hossain Mithun, an Excel and VBA Content Developer at Softeko's ExcelDemy project, joined in October 2021. Holding a Naval Architecture & Marine Engineering degree from BUET, Mithun showcases expertise during his two-year tenure. With over 200 published articles on Excel topics, he earned a promotion to Team Leader, excelling in leading diverse teams. Mithun's passion extends to Advanced Excel, Excel VBA, Data Analysis, and Python programming, contributing significantly to the innovative and dynamic environment of ExcelDemy... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo