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.
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 INSTRREV function in Microsoft Excel is:
InStrRev ( string, substring [, start [ , compare] ] )
The syntax for the INSTRREV function in Microsoft Excel is:
InStrRev ( string, substring [, start [ , compare] ] )
Parameters or Arguments
- string
- The string to search within.
- substring
- The substring that you want to find.
- start
- 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
-
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
- string
- The string to search within.
- substring
- The substring that you want to find.
- start
- 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
- 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.
- 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
- Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
- Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
Type of Function
- VBA function (VBA)
- 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: 0
For example:
Dim LPosition As Integer
LPosition = InStrRev ("alphabet", "a")
In this example, the variable called LPosition would now contain the value 5.
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: 0
For example:
Dim LPosition As Integer LPosition = InStrRev ("alphabet", "a")
In this example, the variable called LPosition would now contain the value 5.