12

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?

Erik A
  • 31,639
  • 12
  • 42
  • 67
Nexus
  • 811
  • 3
  • 9
  • 20

2 Answers2

17

Try InstrRev instead - see here

Note the different syntax to InStr:

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

barrowc
  • 10,444
  • 1
  • 40
  • 53
2

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)
Calum
  • 84
  • 1
  • 6