VBA find Last
VBA中用InStr函数可以查找字符串中第1个出现的位置(VBA是1-Base index),若未出现则返回0。
反复调用它,直到字符串后边检查不到相应字符串,则返回上一次检索到的位置,这样就得到了最后一次出现的位置。
Function findLast(pattern, str) As Integer
currIndex = InStr(1, str, pattern)
Do While True
lastIndex = currIndex
currIndex = InStr(1 + currIndex, str, pattern)
If currIndex = 0 Then
findLast = lastIndex
Exit Do
End If
Loop
End Function