VBA RTrim function

LTrim Function Description

The VBA RTrim function removes trailing whitespaces from a string, looking from the right side of the string.

To remove leading whitespaces see LTrim, to remove both trailing and leading whitespaces see Trim.

Syntax

The syntax for the RTrim function in VBA is:

RTrim( text )

Parameters

text
The string for which you wish to remove any trailing (looking from the right) whitespaces from.

Other Notes

RTrim does not remove non-whitespace characters such as new lines (vbNewLine, vbCrLf) etc.

Example usage

The RTrim function can be used in VBA code. Let’s look at some VBA RTrim function examples:

RTrim "Hello world!   "
'Result: "Hello world!"

RTrim "   Hello world!   "
'Result: "   Hello world!"

RTrim " Some Text " & vbNewLine & "   "
'Result: " Some Text " & vbNewLine