VBA LTRIM Function

VBA LTRIM Function in Excel

VBA LTrim function in Excel is categorized as a Text/String function in VBA. It is a built-in function in MS Office Excel. It removes leading spaces from a given string. It has one mandatory String parameter. If input string has Null, then it returns null.

We use this function only in VBA function. We can’t use this function in Excel worksheet. The LTrim function can be used in either procedure or function in a VBA editor window in Excel. We can use this VBA LTrim function any number of times in any number of procedures or functions. In the following section we learn what is the syntax and parameters of the LTrim function, where we can use this LTrim function and real-time examples in VBA.

Syntax of VBA LTrim Function

The syntax of the VBA LTrim function is

LTrim (String)

Note: This LTrim function removes leading spaces from a given string.

Parameters or Arguments

This function has one mandatory parameter or argument for the LTrim Function.
Where
string: The string is a mandatory argument. The string which we want to convert to Upper case letters.

Where we can apply or use the VBA LTrim Function?

We can use this VBA LTrim function in MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.

Example 1: Remove Leading spaces from a given string:” Awesome1234@# “

Here is a simple example of the VBA LTrim function. This below example macro removes leading spaces (left side) from a given string.

'Remove Leading spaces from a given string:"   Awesome1234@#   "
Sub VBA_LTrim_Function_Ex1()

    Dim sString As String, sSubString As String
    
    sString = "   Awesome1234@#   "
    
    sSubString = LTrim(sString)
    
    MsgBox "(" & sSubString & ")", vbInformation, "VBA LTrim Function"

End Sub

Output: Here is the screen shot of the first example output.
VBA LTRIM Function

Example 2: Remove Leading spaces from a given string:”Awesome1234@# “

Here is a simple example of the VBA LTrim function. This below example macro does not affect anything, because there are no leading spaces in a given string.

'Remove Leading spaces from a given string:"Awesome1234@#   "
Sub VBA_LTrim_Function_Ex2()

    Dim sString As String, sSubString As String
    
    sString = "Awesome1234@#   "
    
    sSubString = LTrim(sString)
    
    MsgBox "(" & sSubString & ")", vbInformation, "VBA LTrim Function"

End Sub

Output: Here is the screen shot of the second example output.
VBA LTRIM Function

Example 3: Remove Leading spaces from a given empty string with spaces:” “

Here is a simple example of the VBA LTrim function. This below example macro removes leading spaces and returns an empty string.

'Remove Leading spaces from a given empty string with spaces:"   "
Sub VBA_LTrim_Function_Ex3()

    Dim sString As String, sSubString As String
    
    sString = "   "
    
    sSubString = LTrim(sString)
    
    MsgBox "(" & sSubString & ")", vbInformation, "VBA LTrim Function"

End Sub

Output: Here is the screen shot of the third example output.
VBA LTRIM Function

Example 4: Remove Leading spaces from a given string:” 12345″

Here is a simple example of the VBA LTrim function. This below example macro removes leading spaces of a given string.

'Remove Leading spaces from a given string:"   12345"
Sub VBA_LTrim_Function_Ex4()

    Dim sString As String, sSubString As String
    
    sString = "   12345"
    
    sSubString = LTrim(sString)
    
    MsgBox "(" & sSubString & ")", vbInformation, "VBA LTrim Function"

End Sub

Output: Here is the screen shot of the fourth example output.
VBA LTRIM Function

Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays in Excel Blog

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers

Leave a Reply