VBA – Right String
The Right function in VBA extracts a specified number of characters from the right side of a given string.
Right
Syntax:
Right(string, length)
Parameter:
Return Value:
Example: Extract the last 3 characters
Dim str1 As String Dim rightStr As String str1 = "Hello, World!" rightStr = Right(str1, 3) ' rightStr will be "d!"
Extract more characters than the string length:
Dim str1 As String Dim rightStr As String str1 = "Hello, World!" rightStr = Right(str1, 15) ' rightStr will be "Hello, World!" (Returns the entire string)
Use Cases:
Key Considerations:
length