INSTRREV

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

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


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

REMARKS
* This function is case sensitive (by default).
* This function does not support wildcards (? and *).
* 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" if left blank, then -1 is used (meaning the last character).
* If "start" > Len("stringcheck"), then 0 is returned.
* If "start" is Null, then an error occurs.
* If "compare" is left blank, then -1 is used.
* If "compare" = -1 but there is no Option Compare statement provided, then vbBinaryCompare is used.
* If "compare" is Null, then an error occurs.
* You can use the INSTR function to return the position of a substring within a larger string, starting at the beginning.
* You can use the MID Function to return a substring from the middle, left or right of a string.
* You can use the LIKE Operator to pattern match using wildcards.
* For more information, refer to the Finding Strings page.
* The equivalent .NET function is Microsoft.VisualBasic.Strings.InStrRev
* For the Microsoft documentation refer to learn.microsoft.com

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

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