INSTRREV(stringcheck, stringmatch [,start] [,compare])

Returns the position of a substring within a larger string, starting at the end (Long).

stringcheckThe text string containing your substring (String).
stringmatchThe text string to look for (String).
start(Optional) The number of the character to start looking from.
compare(Optional) A vbCompareMethod constant specifying the type of string comparison to use (Integer):
-1 = vbUseCompareOption (uses the "Option Compare" setting)
0 = vbBinaryCompare (default, case sensitive)
1 = vbTextCompare (not case sensitive)
2 = vbDatabaseCompare (uses an Access database)

* This function is case sensitive (by default).
* This function is similar to INSTR except it starts searching at the end of the string, rather than at the beginning.
* This function makes it very easy to parse a folder/file path and return just the filename.
* Although this function searches from the right hand side of the string, it counts characters from the left (the same as Instr).
* If "stringcheck" = "" (zero length string), then 0 is returned.
* If "stringcheck" is Null, then Null is returned.
* If "stringmatch" = "" (zero length string) then "start" is returned.
* If "stringmatch" cannot be found in "stringcheck" then 0 is returned.
* If "stringmatch" is Null, then Null is returned.
* If "start" > Len("stringcheck"), then 0 is returned.
* If "start" if left blank, then -1 is used (meaning the last character).
* If "start" is Null, then an error occurs.
* If "compare" is left blank, then -1 is used. If there is no Option Compare statement provided then vbBinaryCompare (0) is used.
* If "compare" is Null, then an error occurs.
* You can use the INSTR function to start at the beginning.
* You can use the MID function to return the text string which is a substring of a larger string.
* For more information, refer to the Finding Strings page.
* The equivalent .NET function is Microsoft.VisualBasic.Strings.InStrRev
* For the Microsoft documentation refer to

Debug.Print InStr("C:\Temp\","C:\")                  '= 1  
Debug.Print InStrRev("C:\Temp\","C:\") '= 1
Debug.Print InStr("C:\Temp\","\") '= 3
Debug.Print InStrRev("C:\Temp\","\") '= 8
Debug.Print InStrRev("somemoretext","more") '= 5
Debug.Print InStrRev("somemoretext","somemoretext") '= 1
Debug.Print InStrRev("somemoretext","nothing") '= 0
Debug.Print InStrRev("bettersolutions","better") '= 1
Debug.Print InStrRev("bettersolutions","solutions") '= 7

Dim lPosition As Long
lPosition = InStrRev("Monday","day")
Debug.Print lPosition

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited Top