Excel VBA LTrim Function

VBA LTrim Function: The LTrim function in VBA removes the leading spaces from a supplied text string.

Syntax

LTrim (String)

Parameter

String (required) - This parameter represents he text string that you want to remove the leading spaces from.

Return

This parameter returns a string after removing the leading spaces.

Example 1

Sub LTrimFunction_Example1()
 'Remove the leading spaces from two strings.
 Dim name As String, address As String
 name = " Joe Jonas"     ' has a leading space
 address = "     Street   34 Manhattan, US   "     ' has several leading spaces
 name = LTrim(name)
 ' The function will return the varaible name = "Joe Jonas"
 Cells(1, 1).Value = "Name : " + name
 address = LTrim(address) 
 ' address: "Street 34 Manhattan, US"
 Cells(1, 2).Value = "Address: " + address
 End Sub 

Output

Name : Joe Jonas Address: Street   34 Manhattan, US  
VBA LTrim Function

Example 2

Sub LTrimFunction_Example2()
 'Remove the leading spaces from two strings.
 Dim name As String, address As String
 IB = InputBox("Enter your first name")
 Lst_IB = InputBox("Enter your last name")
 'will the id after removing the spcaes and convering the string into lower case
 MsgBox ("Your email is: " + LTrim(LCase(IB)) + LTrim(LCase(Lst_IB)) + "@gmail.com") 
 End Sub 

Output

Enter your first name and click on OK

VBA LTrim Function

Enter your last name. Click on Ok

VBA LTrim Function

A MsgBox will pop up displaying your email id

VBA LTrim Function