How to Remove Space in Excel after Text (6 Quick ways)

Remove Space after Text in Excel

We have a list of names with unwanted spaces after text. We want to remove those spaces to perform further operations. We have included two columns, Normal Text and Text without Unwanted Space.

Remove Space in Excel after Text


How to Remove Space after Text in Excel: 6 Quick Ways


Method 1 – Remove Spaces in Excel after Text Using Find and Replace

  • Select the range to apply the Find and Replace feature. We selected the range B5:B9.

  • Go to the Home tab and click on the Find & Select option in the toolbar.

Remove Space in Excel after Text

  • From Find & Select, select Replace.

  • The Find and Replace dialogue box will appear.

Remove Space in Excel after Text

  • In the Find what box, put a single space.
  • Leave the Replace with box blank.

Remove Space in Excel after Text

  • Press Replace All. A message box will appear with the number of replacements.

  • All the spaces after text will disappear.

Read More: How to Remove Space Before Text in Excel


Method 2 – Remove Spaces after Text Using the TRIM Function in Excel

Case 2.1 – Using the TRIM Function Only

  • Use the following formula in cell C5.
=TRIM(B5)

Remove Space in Excel after Text

  • Press Enter.

  • Drag the Fill Handle down to AutoFill the column.

Remove Space in Excel after Text


Case 2.2 – Using LEN and LEFT Functions with the TRIM Function

  • Use the following function in C5.
=TRIM(LEFT(B5,LEN(B5)))

Formula breakdown

LEN(B5)—> measures the length of the characters in cell B5. In this case,
          Output is : 14

LEFT(B5,LEN(B5))—> becomes LEFT(B5,14). So,it takes into account 14 characters from the left. In this case,
        Output is : Abagail   Ross
        Explanation : There are 2 extra spaces between the words.

TRIM(LEFT(B5,LEN(B5)))—> now the TRIM Function comes into action. It removes the two extra spaces between the words and gives us the appropriate result.
        Output is : Abagail Ross
        Explanation : Notice that there is no extra space between two words.

  • Press Enter.

Remove Space in Excel after Text

  • Drag the Fill Handle down to AutoFill the column.

Read More: How to Remove Leading Spaces in Excel


Method 3 – Remove Spaces after Text Using Power Query

  • Select the entire dataset.

Remove Space in Excel after Text

  • We selected the range B5:B9.

  • Select From Table/ Range from the Data tab.

Remove Space in Excel after Text

  • A new window will pop up.

  • Go to Add Column, then to Format, and select TRIM.

Remove Space in Excel after Text

  • We will get the trimmed data in a new column named Trim.

Remove Space in Excel after Text

  • Go to the File tab.

  • Click Close & Load.

Remove Space in Excel after Text

  • You will get the results in a new sheet.


Method 4 – Remove Spaces after Text Using Macros and VBA

  • Select the entire range.

  • We selected the range B5:B9.

Remove Space in Excel after Text

  • Open the Developer tab and select Visual Basic

  • A new window will appear.

Remove Space in Excel after Text

  • Go to the Insert tab and select Module.

  • A new Module will appear. Insert the code below in the new Module.
Sub RemoveSpacesafterText()
Dim M As range
Dim cell As range
Set M = Selection
For Each cell In M
If Not IsEmpty(cell) Then
cell = Trim(cell)
End If
Next cell
End Sub

Remove Space in Excel after Text

We used a For loop to find every cell that has unwanted spaces. The VBA TRIM function will remove spaces.

  • Save the code and run it by pressing F5.

Remove Space in Excel after Text


Method 5 – Remove Spaces after Text Using the LEFT Function in Excel

If we know how many spaces there are on the right of the text (i.e., after the text), we can remove the spaces using the LEFT function.

Remove Space in Excel after Text

  • We have three spaces on the right of the text. In cell C5, insert the following:
=LEFT(B5,LEN(B5)-3)

Formula Breakdown

LEN(B5) —> gives us the length of the value in cell B5.
         Output is : 10

LEN(B5)-3 —> gives us the value of 10-3.
         Output is : 7
         Explanation: We find the number of characters required.

LEFT(B5,LEN(B5)-3) —> retrieves 7 characters from the left of the text.
         Output is : Abagail
         Explanation: No extra space after the text.

  • Press Enter key to get the value in cell C5.

  • By dragging down the Fill Handle to use the AutoFill feature, we will get all the values in the Text Without Unwanted Space column.

Remove Space in Excel after Text

  • However, if you have a different number of spaces in other cells, the formula won’t work.

Method 6 – Remove Spaces after Text Using the SUBSTITUTE Function in Excel

We will replace the extra spaces between two words.

  • In the C5 cell, use the following formula:
=SUBSTITUTE(B5,"  ","")

The SUBSTITUTE function will substitute any instance of two spaces it can find with a blank character.

  • Press Enter.

Remove Space in Excel after Text

  • Use the Fill Handle to AutoFill the corresponding values in the Text Without Unwanted Space column.

Read More: How to Remove Space in Excel before Numbers


Practice Section

We have included a practice section so that you can practice the methods on your own.

Remove Space in Excel after Text


Download the Practice Workbook


Related Articles

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

Get FREE Advanced Excel Exercises with Solutions!
Lutful Hamid
Lutful Hamid

LUTFUL HAMID is an outstanding marine engineer who finds joy in navigating the realms of Excel and diving into VBA programming. To him, programming is like saving time when dealing with data, files, and the internet. His skills extend beyond the basics, covering Rhino3D, Maxsurf C++, MS Office, AutoCAD, and Excel & VBA. Armed with a B.Sc in Naval Architecture & Marine Engineering from BUET, he's shifted gears and now serves as a content developer. In this role,... Read Full Bio

1 Comment
  1. Thank you. This helped me to remove spaces in the end of text through Power query.

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo