TOP

VBA Function: Right

YouLibreCalc for Excel logo

Description

The VBA RIGHT Function returns the specified number of characters from a string starting from the right.


RIGHT Syntax

Right(text, number_characters)

VBA Right Example

Retrieve a variable number of characters from the same string starting from the right:

Sub RightExample()
    
     MsgBox Right("www.moonexcel.com.ua", 1)  'Returns: a
     MsgBox Right("www.moonexcel.com.ua", 2)  'Returns: ua
     MsgBox Right("www.moonexcel.com.ua", 3)  'Returns: .ua
     MsgBox Right("www.moonexcel.com.ua", 4)  'Returns: m.ua
     MsgBox Right("www.moonexcel.com.ua", 5)  'Returns: om.ua
     MsgBox Right("www.moonexcel.com.ua", 10) 'Returns: cel.com.ua
     MsgBox Right("www.moonexcel.com.ua", 50) 'Returns: www.moonexcel.com.ua

End Sub
The function that returns the specified number of characters from the left is the LEFT function.
To extract characters inside a string, you can use the MID function.