How to remove leading spaces in cells in Excel?

Sometimes there are some blank spaces before strings in cells, these spaces are called leading spaces. It must be arduous to remove leading spaces in cells one by one. Actually, there are several smart tricks that can help us remove leading spaces in cells conveniently and quickly.

Remove leading spaces in cells with Trim function

Remove leading spaces in cells with VBA

Remove leading spaces in cells with Kutools for Excel

Suppose we paste some content from Microsoft Word with indent spaces, then it shows the leading spaces in each cell as the following screenshot shows.

Kutools for Excel: add 120 new features in Excel. Save one hour every day.
Classic Menu for Office: brings back classic menus to Office 2010 and 2013 (includes Office 365).
Office Tab: brings tabbed interface to Office as the use of web browser Chrome, Firefox and Internet Explorer.

Hot
Amazing! Using Tabs in Excel like Firefox, Chrome, Internet Explore 10!

arrow blue right bubble Remove leading spaces in cells with Trim function

The Trim function in Microsoft Excel can remove all spaces from text except for single spaces between words.

Step 1: Enter the formula =TRIM (A1) in the adjacent cell C1.

Step 2: Press Enter key and select the cell C1, then drag the fill handle over the range cell that you want to contain this formula. And all of the leading spaces have been removed from the text strings. See screenshot:

As they are formulas, so you need to copy and paste them as values.

This method is quite easy if you only need to remove leading spaces in contiguous cells within a row or a column. However, when you need to remove leading spaces in a range with several rows and columns, you have to use the function several times.


arrow blue right bubble Remove leading spaces in cells with VBA

If you are experienced with Microsoft Excel,  VBA macro is a better choice to remove the leading spaces in cells.

Step 1: Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

Step 2: Click Insert > Module, and paste the following macro in the Modulewindow.

VBA: Remove leading spaces:

Sub RemoveLeadingSpace()
'Updateby20131129
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
Rng.Value = VBA.LTrim(Rng.Value)
Next
End Sub

Step 3: Press the F5 key to run this macro. And a pop-up dialog is for you to select a range to work, see screenshot:

Step 4: Click OK, you can see all the leading spaces have been removed, see screenshots:


arrow blue right bubble Remove leading spaces in cells with Kutools for Excel

If you have Kutools for Excel installed, you can remove all leading spaces of cells in a selection conveniently and quickly.

Kutools for Excel includes more than 120 handy Excel tools. Free to try with no limitation in 30 days. Get it Now.

Step 1: Select the range which you want to remove all leading spaces in cells.

Step 2: Click the Kutools > Text Tools > Remove Spaces. See screenshot:

doc-remove-leading-spaces4

Step 3: In Remove Spaces dialog box, check the Leading Spaces option in Spaces Type section. See screenshot:

Step 4: Click OK or Apply. And all of the leading spaces will be removed.

Kutools for Excel's Remove Spaces tool makes it possible to delete all kinds of spaces from strings in cells, including all extra spaces, leading spaces, trailing spaces, or all spaces.Click to know more...


Related articles:


Kutools for Excel

More than 120 Advanced Functions for Excel 2013, 2010, 2007 and Office 365.

screen shot

btn read more     btn download     btn purchase

Add comment


Security code
Refresh