The VBA LTrim function removes the leading spaces from a supplied text string.
The syntax of the function is:
Where the String argument is the text string that you want to remove the leading spaces from.
The following example shows how the VBA LTrim function can be used to remove one or more leading spaces from two different text strings.
' Remove the leading spaces from two text strings.
Dim name As String
Dim address As String
name = " John Smith" ' has a leading space
address = " 21 Smithson Street" ' has several leading spaces
name = LTrim( name )' After running the above code, name = "John Smith" and
address = LTrim( address )
' address = "21 Smithson Street"
Note that the LTrim function only removes leading spaces (not trailing spaces) from the supplied text string. If you wish to remove trailing spaces, you will need to use the VBA RTrim or the VBA Trim function.