VBA RTrim Function

Related Functions:
VBA LTrim
VBA Trim

Description

The VBA RTrim function removes the trailing spaces from a supplied text string.

The syntax of the function is:

RTrim( String )

Where the String argument is the text string that you want to remove the trailing spaces from.


VBA RTrim Function Examples

The following example shows how the VBA RTrim function can be used to remove one or more trailing spaces from two different text strings.

' Remove the trailing spaces from two text strings.
Dim name As String
Dim address As String
name = "John Smith "     ' has a trailing space
address = "21 Smithson Street     "     ' has several trailing spaces
name = RTrim( name )
address = RTrim( address )
' After running the above code, name = "John Smith" and
' address = "21 Smithson Street"

Note that the RTrim function only removes trailing spaces (not leading spaces) from the supplied text string. If you wish to remove leading spaces, you will need to use the VBA LTrim or the VBA Trim function.