代码功能:从右边开始查找字符。
Public Function MyInStrRev(MainStr As String, SubStr As String) As Integer
Dim Counter As Integer
Dim Success As Boolean
If VBA.Len(MainStr) < VBA.Len(SubStr) Then
MyInStrRev = 0
Else
For Counter = VBA.Len(SubStr) To VBA.Len(MainStr)
If VBA.Left(VBA.Right(MainStr, Counter), VBA.Len(SubStr)) = SubStr Then
Success = True
Exit For
End If
Next Counter
If Success Then
MyInStrRev = VBA.Len(MainStr) - Counter + 1
Else
MyInStrRev = 0
End If
End If
End Function
知识拓展:
查找右边第一个"]"所在位置 (右起第3位)
=LEN(A1)-FIND("@",SUBSTITUTE(A1,"]","@",LEN(A1)-LEN(SUBSTITUTE(A1,"]",""))),1)+1
LEN(A1)-LEN(SUBSTITUTE(A1,"]",""): 字符串长度 - 不为"]"的个数 = 3
SUBSTITUTE(A1,"]","@",LEN(A1)-LEN(SUBSTITUTE(A1,"]",""))) 用"☆"替换第3次出现的"]"
FIND("@",SUBSTITUTE(A1,"]","@",LEN(A1)-LEN(SUBSTITUTE(A1,"]",""))),1) 从第一个字符开始找到"@"第一次出现的位。