Access VBA has Instr to return the position of the first occurrence of a string in another string.
Instr ( [start], string_being_searched, string2, [compare] )
Is there any method to return the position of the last occurrence of a string in another string?
The strrchr() function finds the last occurrence of c (converted to a character) in string.
VBA INSTRREV Function, as stands for 'In String Reverse', returns the position of the first occurrence of a search string (substring) in another string, starting from the end of the string (from right to left) from which we are looking for a searchable string.
The Microsoft Access InStr function returns the position of the first occurrence of a string in another string.
Find the Last Occurrence of a String In Another String. If we want to find whether or not a character or string occurs within another string we can use FIND or SEARCH. But these functions only tell us if a string (or character) exist in another string, they don't tell us if the string we are looking for occurs multiple times.
For the second method, we’re going to use the MATCH function, the SEQUENCE function, the MID function, and the LEN function to find the position of the last occurrence of a character in the string. Remember the SEQUENCE function is only available on Excel 365 or Excel 2021.
You can also use the InstrRev function in a query in Microsoft Access. This query will return the position of the last "v" in the LastName field. The results will be displayed in a column called Expr1. You can replace Expr1 with a column name that is more meaningful.
For the first method, we’re going to use the FIND function, the SUBSTITUTE function, the CHAR function, and the LEN function to find the last position of the slash in our string. Firstly, type the following formula in cell D5. Our main function is FIND. We’re going to find the CHAR (134) value in our string. Output: †.
Try InstrRev
instead - see here
Note the different syntax to InStr
:
InstrRev(stringcheck, stringmatch[, start[, compare]])
Check this link, example code from MS
https://msdn.microsoft.com/en-us/library/t2ekk41a(v=vs.90).aspx
Dim TestString As String = "the quick brown fox jumps over the lazy dog"
Dim TestNumber As Integer
' Returns 32.
TestNumber = InStrRev(TestString, "the")
' Returns 1.
TestNumber = InStrRev(TestString, "the", 16)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With