VBA - Right


Advertisements

The Right function returns a specified number of characters from the right side of the given input string.

Syntax

Right(String, Length)

Parameter Description

  • String − A required parameter. Input String from which the specified number of characters to be returned from the right side.

  • Length − A required parameter. An Integer, which Specifies the number of characters to be returned.

Example

Add a button and add the following function.

Private Sub Constant_demo_Click()
   var = "Microsoft VBScript"
   msgbox("Line 1 : " & Right(var,2))
   
   var = "MS VBSCRIPT"
   msgbox("Line 2 : " & Right(var,5))
   
   var = "microsoft"
   msgbox("Line 3 : " & Right(var,9))
End Sub

When you execute the above function, it produces the following output.

Line 1 : pt
Line 2 : CRIPT
Line 3 : microsoft
vba_strings.htm
Advertisements