How To Remove Spaces In Excel

  • Home
  • / How To Remove Spaces In Excel

Abstract

Many times, data is entered into Excel workbooks with spaces. These unwanted spaces might be at the beginning of the data or at the end or even sometimes in between strings. So, the thing is how to remove spaces in Excel?

These spaces can cause issues when you try to analyze the data and create reports out of it. The following options will help you remove spaces in Excel sheets.

Remove extra spaces in Excel through the GUI

Level of difficulty: LOW

Find and Replace:

This option helps you to remove spaces in Excel’s single sheet or you may remove spaces from all sheets in your workbook. This option will help you to remove leading spaces, trailing spaces, and even spaces in between strings. You also have the option to remove spaces from a selected range. The following steps will help you use Excel’s find and replace option to remove spaces through the GUI.

Step 1: Select the range from which you want to remove extra spaces in Excel.

Step 2: From the Home header in the Excel ribbon, select “Editing”. Then click on “Find & Select” and choose “Replace”. If you are comfortable in using keyboard shortcuts, press “Ctrl + H” to open the Find & Replace wizard.

Step 3: On the wizard, under the tab “Header” you will see two text boxes. The first text box is “Find What:” and the second text box is the “Replace with:” field. In the “Find What:” text box type a space and leave the “Replace with:” with a NULL value.

Step 4: The wizard will also have 3-drop downs. The first drop-down allows the user to do the find and replace within the sheet or at the workbook level. The second drop-down makes the search at Row level or at the column level. The third drop-down makes Excel search on formulas or on values.

Step 5: Click on “Replace All” to remove all spaces from your data.

How to Remove spaces in Excel through Formula

Level of difficulty: LOW

TRIM

This inbuilt excel function helps you to remove leading and trailing spaces from your Excel data. However, this will not remove spaces between strings. The only drawback with this option is, you must type and apply the formula in a separate cell, then copy it and using ‘paste special’ to paste it as value.

Step 1: Use an existing empty column or create a new column and start typing the formula = TRIM (CELL_ADDRESS). Please note that you have to update the CELL_ADDRESS in this formula with the actual address of the starting cell in your Excel range.

Step 2: Press enter to see the leading and trailing spaces being removed from the data in the selected cell.

Step 3: Select the cell in which you typed the formula. Click and drag the bottom-right corner of it until you reach the last cell in the excel range.

Step 4: The new column will now contain the same data from the selected range. However, this will not contain the leading and trailing spaces. This new column will still contain the formulas within it. We should remove the formulas without affecting the displayed data.

Step 5: Select all cells in this new column, copy them, and then using ‘paste special’ paste the values. You can paste data directly on your original column or into a new column.

SUBSTITUTE

This inbuilt excel function helps you to remove leading space, trailing space, and spaces between your Excel data. As the name implies, this function substitutes space with the replacing character that you input in the formula. The syntax is = SUBSTITUTE (Text, Old text, New Text)

As shown below, for the first parameter, you can pass a string or you can pass a CELL address. In the place of Old text, you have to mention an empty space and in the place of New Text, you can pass a NULL value.

= SUBSTITUTE (A2,” “,””)

How To Remove Spaces In Excel 1

Remove spaces using user define a function

Level of difficulty: MEDIUM

TRIM clears both leading and trailing spaces. Nevertheless, it does not allow you to clear either the leading space or the trailing space. However, you can achieve this using user-defined function. To build your custom functions, you would be using the function LTRIM and RTRIM, which is available only with VBA. LTRIM removes the leading space and RTIM removes trailing spaces in Excel sheet.

Step 1: If you are on worksheets, press Alt+F11 to open the VBA editor.

Step 2: Right-click on the VBA project at the left, select the option ‘Insert’ and then click “Module”. This will insert a new module into your VBA project.

Step 3: Copy these scripts into your module and save your workbook as a macro-enabled file. The first script will create a new user-defined function with which you can remove leading spaces from a string. The second script will create a new user-defined function with which you can remove trailing spaces in Excel.How To Remove Spaces In Excel 2

Step 4: You can now use these user-defined functions in your Worksheet formulas or in your VBA scripts.

Step 5: Below is an example for using this user-defined function in the Worksheet formula.

This will remove leading space from the Cell A2;

Please note that our guide applies to Excel 2016 and might vary across versions of Excel.

Write your comment Here