How to Remove Blank Spaces in Excel -7 Methods

This sample dataset contains cells with multiple blank spaces.

dataset

Method 1 – Using the TRIM Function to Remove Blank Spaces

  • Enter the following formula in an empty cell (A16).
=TRIM(A5)

The TRIM function will remove extra blank spaces from A5.

trim

  • Press ENTER and no blank spaces will be displayed in A16.

remove blank spaces

  • Drag A16 to apply the formula to all other cells in column A.

apply in all cells

Read More: How to Remove Space Before Text in Excel


Method 2 – Using the Find and Replace Command

  • Go to Home> Editing > Find & Select > Replace

find and replace

  • In the Find and Replace window, enter a single space in Find what box and click Replace All.

find and replace box

  • Click OK in the confirmation box and close the Find and Replace window.

confirmation box

All blank spaces have been removed.

remove blank spaces

Method 3- Using the SUBSTITUTE Function to Remove Blank Spaces

You can also use the SUBSTITUTE function to remove blank spaces. Enter the following formula in B16.

=SUBSTITUTE(B5, " ", "")

The substitute function will remove the spaces in B5.

SUBSTITUTE FUNCTION in Excel

  • Press ENTER and the text will be displayed without blank spaces in B16.

remove blank spaces in Excel

  • Drag B16 to apply the formula to all other cells in column B.

remove blank spaces in all cell


Method 4 – Remove a Blank Space using the REPLACE Function

  • The REPLACE function can also remove blank spaces. Enter the following formula in B16.
=REPLACE(B5,1,LEN(B5)-LEN(TRIM(B5)),"")

The LEN function indicates the length of the string in B5. LEN(B5)-LEN(TRIM(B5)  gives the number of blank spaces. The REPLACE function replaces the original text with the string without blank spaces.

REPLACE FUNCTION IN EXCEL

  • Press ENTER to see the text without blank spaces in B16.

REMOVE BLANK SPACES IN EXCEL

  • Drag B16 to apply the formula to all other cells in column B.

REMOVE BLANK SPACES

Method 5 – Using the Text to Column Feature to Remove Blank Spaces

  • Select the column and go to Data> Data Tools > Text to Columns

TEXT TO COLUMNS

  • In the Convert Text to Columns Wizard window, select Fixed width and click Next.

TEXT TO COLUMN WIZARD

  • Move the vertical line to the end of your text and click Next.

TEXT TO COLUMN WIZARD

  • Select General and click Finish.

REMOVE BLANK SPACES IN EXCEL

  • Cells in the selected columns have no blank spaces.

REMOVE BLANK SPACES IN EXCEL

Method 6 – Using a VBA to Remove Blank Spaces

  • Press ALT+F11 to open the VBA window.
  • In Project,  right-click the sheet name.
  • Choose Insert from the dropdown menu and select Module.

VBA

A Module(Code) window will be displayed.

MODULE

  • Enter the following code in the Module.
Sub Remove_Blanks()

Dim x As Range

For Each x In Selection.Cells

x.Value = VBA.Trim(x.Value)

Next x

End Sub

CODE

  • Close the VBA window. Select your dataset and go to View > Macros.

MACRO

  • A Macro window will open. Click Run.

MACRO BOX

All blank spaces will be removed.

REMOVE BLANK SPACES IN EXCEL

Method 7 – Using the Power Query to Remove Blank Spaces

  • Select your dataset and go to Data > Get Data > From Other Sources > From Table/Range

TABLE

  • A Create Table dialog box will open. Click OK.

CREATE TABLE

The Power Query Editor window will open.

POWER QUERY

All your data is displayed.

DATA IN POWER QUERY

  • Right-click any header and select Transform > Trim.

  • Repeat the same procedure for all the columns. Blank spaces will be removed.

REMOVE BLANK SPACES IN EXCEL

  • In the home tab, select Close & Load.

IMPORT FROM POWER QUERY

Data will be displayed in a new sheet: Table.

Remove blank spaces in EXCEL

Download Practice Workbook


Related Articles

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

Get FREE Advanced Excel Exercises with Solutions!
Prantick Bala
Prantick Bala

PRANTICK BALA is a marine engineer who loves exploring Excel and VBA programming. Programming, to him, is a time-saving tool for efficiently managing data, files, and internet tasks. He is proficient in Rhino3D, Maxsurf, C++, MS Office, AutoCAD, Excel, and VBA and goes beyond the basics. Armed with a B.Sc in Naval Architecture & Marine Engineering from BUET, he has transitioned into the role of a content developer. Beyond his work, find him immersed in books, exploring new... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo