Excel VBA RTrim Function
VBA RTrim Function: The Rtrim function in VBA removes the leading spaces from the text in the specified string.
Syntax
RTrim (String)
Parameter
String (required) – This parameter represents the string from which you want to remove the trailing spaces.
Return
This function returns a string after removing the trailing spaces.
Example 1
Sub RTrimFunction_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 = RTrim(address) ' address: "Street 34 Manhattan, US" Cells(1, 2).Value = "Address: " + address End Sub
Output
Name : Joe Jonas | Address: Street 34 Manhattan, US |
Example 2
Sub RTrimFunction_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: " + RTrim(LTrim(LCase(IB))) + RTrim(LTrim(LCase(Lst_IB))) + "@gmail.com") End Sub
Output