VBA RTRIM Function (Syntax + Example)

Last Updated: June 22, 2023
puneet-gogia-excel-champs

- Written by Puneet

The VBA RTRIM function is listed under the text category of VBA functions. When you use it in a VBA code, it can remove the ending spaces from the string supplied. In simple words, it can remove all those unwanted ending spaces from a string.

Syntax

RTrim(String)

Arguments

  • String: The text string from which you want to remove the trailing spaces.

Example

To practically understand how to use the VBA RTRIM function, you need to go through the below example where we have written a vba code by using it:

example-vba-rtrim-function
Sub example_RTRIM()
Range("B1").Value = RTrim(Range("A1"))
End Sub

In the above code, we have used the RTRIM function to remove the unwanted spaces from the right side of cell A1.

Notes

  • If the supplied string is NULL, then it will return NULL in the result.