This Excel tutorial explains how to use the Excel INSTRREV function with syntax and examples.
substring is the substring that you want to find.
start is optional. It is the starting position for the search. If this parameter is omitted, the search will begin at position -1 which is the last character position.
compare is optional. It is the type of comparison to perform. It can be one of the following values:
Let's look at some Excel INSTRREV function examples and explore how to use the INSTRREV function in Excel VBA code:
Description
The Microsoft Excel INSTRREV function returns the position of the first occurrence of a string in another string, starting from the end of the string. This is similar to the INSTR function which returns the position of the first occurrence, starting from the beginning of the string.Syntax
The syntax for the Microsoft Excel INSTRREV function is:InStrRev ( string, substring [, start [ , compare] ] )
Parameters or Arguments
string is the string to search within.substring is the substring that you want to find.
start is optional. It is the starting position for the search. If this parameter is omitted, the search will begin at position -1 which is the last character position.
compare is optional. It is the type of comparison to perform. It can be one of the following values:
VBA Constant | Value | Explanation |
---|---|---|
vbUseCompareOption | -1 | Uses option compare |
vbBinaryCompare | 0 | Binary comparison |
vbTextCompare | 1 | Textual comparison |
Note
- If string2 is not found within string_being_searched, the INSTRREV function will return 0.
- If string_being_searched is zero-length, the INSTRREV function will return 0.
- If string_being_searched is null, the INSTRREV function will return null.
- If start is null, the INSTRREV function will return #Error.
Applies To
The INSTRREV function can be used in the following versions of Microsoft Excel:- Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
Type of Excel Function
The INSTRREV function can be used in Microsoft Excel as the following type of function:- VBA function (VBA)
Example (as VBA Function)
The INSTRREV function can only be used in VBA code in Microsoft Excel.Let's look at some Excel INSTRREV function examples and explore how to use the INSTRREV function in Excel VBA code:
InStrRev ("alphabet", "a") Result: 5 InStrRev ("alphabet", "a", -1) Result: 5 InStrRev ("alphabet", "a", 1) Result: 1 InStrRev ("alphabet", "a", 2) Result: 1 InStrRev ("alphabet", "a", 3) Result: 1 InStrRev ("alphabet", "a", 4) Result: 1 InStrRev ("alphabet", "a", 5) Result: 5 InStrRev ("alphabet", "a", 6) Result: 5 InStrRev ("alphabet", "a", 7) Result: 5 InStrRev ("alphabet", "a", 8) Result: 5 InStrRev ("alphabet", "a", 9) Result: 0For example:
Dim LPosition As Integer LPosition = InStrRev ("alphabet", "a")