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.

Recommended Productivity Software

Office Tab: Use tabbed interface in Office as the use of web browser Chrome, Firefox and Internet Explorer.
Kutools for Excel: Adds 120 powerful new features to Excel. Increase your productivity in 5 minutes. Save two hours every day!
Classic Menu for Office: Brings back your familiar menus to Office 2007, 2010 and 2013 (includes Office 365).

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:


Is your problem solved?

Recommended Productivity Tools

The following tools will greatly save your time and effort, which one do you prefer?
Office Tab: Using handy tabs in your Office, as the way of Chrome, Firefox and New Internet Explorer.
Kutools for Excel: 120 powerful new functions for Excel, Increase your productivity in 5 minutes. Save two hours every day!
Classic Menu for Office: Bring back familiar menus to Office 2007, 2010, 2013 and 365, as if it were Office 2000 and 2003.

Kutools for Excel

gold star1 Amazing! Increase your productivity in 5 minutes. Don't need any special skills, save two hours every day!

gold star1 More than 120 powerful advanced functions which designed for Excel:

  • Merge Cell/Rows/Columns without Losing Data.
  • Combine and Consolidate Multiple Sheets and Workbooks.
  • Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency Conversion.
  • Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,
  • More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets Tools...

Screen shot of Kutools for Excel

btn read more     btn download     btn purchase