VBA Function: InStrRev

The VBA InStrRev function returns an integer value corresponding to the first position of a value found within a string, starting the search from the right.

The InStrRev function returns the value 0 if no match is found.


InStrRev(text, value)


InStrRev(text, value, start_num, compare)

Examples of Usage

Using the InStrRev function to determine the position of the value XLP, starting the search from the right of the text:

Sub example()
    referenceNumber = "REF: XLP-54-21-XLP-9"
    'First position of "XLP" when searching from the right
    number = InStrRev(referenceNumber, "XLP")
    MsgBox number 'Returns: 16
End Sub
The function that searches for the position of a value from the left of the text is the InStr function.