VBA Right function

Right Function Description

The VBA Right function extracts a substring from a string, starting with the right-most character (from the end of the string).

Use the Left function to extract characters from the left hand side of the string. Use the Mid function to get a substring from the middle of any string.

Syntax

The syntax for the Right function in VBA is:

Right( text, length )

Parameters

text
The string that you wish to extract from.

length
It indicates the number of characters to extract, starting from the right-most character.

Other Notes

The string index position in the Mid, Left and Right functions starts at 1.

For better performance use the typed version of the Right function: Right$ instead of the default Right. This is because the Right function return a variant instead of a string as therefore impacts performance. For more information on VBA Performanceread here

Example usage

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

Right "Hello", 4
'Result: "ello"

Right "Hello", 10
'Result: "Hello"