VBA Right function

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 4.00 out of 5)
Loading...

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"

Simply the best place to learn VBA!

Error: Please enter a valid email address

Error: Invalid email

Error: Please enter your first name

Error: Please enter your last name

Error: Please enter a username

Error: Please enter a password

Error: Please confirm your password

Error: Password and password confirmation do not match