Skip to main content

InStrRev function

Returns the position of an occurrence of one string within another, from the end of the string.

Syntax

InstrRev(stringcheckstringmatch, [ start, [ compare ]])

The InstrRev function syntax has these named arguments:

Part Description
stringcheck Required. String expression being searched.
stringmatch Required. String expression being searched for.
start Optional. Numeric expression that sets the starting position for each search. If omitted, -1 is used, which means that the search begins at the last character position. If start contains Null, an error occurs.
compare Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. If omitted, a binary comparison is performed. See the Settings section for values.

Settings

The compare argument can have the following values:

Constant Value Description
vbUseCompareOption -1 Performs a comparison by using the setting of the Option Compare statement.
vbBinaryCompare 0 Performs a binary comparison.
vbTextCompare 1 Performs a textual comparison.
vbDatabaseCompare 2 Microsoft Access only. Performs a comparison based on information in your database.

Return values

InStrRev returns the following values:

If InStrRev returns
stringcheck is zero-length 0
stringcheck is Null Null
stringmatch is zero-length start
stringmatch is Null Null
stringmatch is not found 0
stringmatch is found within stringcheck Position at which match is found
start > Len(stringcheck) 0

Remarks

Note that the syntax for the InstrRev function is not the same as the syntax for the Instr function.

InstrRev will not find an instance of stringmatch unless the position of the end character of stringmatch is less than or equal to start.

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>