View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default VBA to delete leading space

The LTrim function removes spaces on the left of a String. For example,

Sub RemoveLeadingSpace()
Dim R As Range
Application.EnableEvents = False
On Error GoTo ErrH:
If TypeOf Selection Is Excel.Range Then
For Each R In Selection.Cells
If R.HasFormula = False Then
R.Value = LTrim(R.Value)
End If
Next R
End If
ErrH:
Application.EnableEvents = True
End Sub


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



"CB" wrote in message
...
I have a column of data that has a leading blank in each cell. Does
someone
have a code example that I can use to delete this leading space? I have
spaces between data in these cells and just need to delete the leading
space
on the left hand side of each cell. Any and all replies are greatly
appreciated.