Function 统计字符串出现次数(sourceStr As String, searchStr As String) As Long
On Error GoTo Error_Handler
统计字符串出现次数 = UBound(Split(sourceStr, searchStr))
Error_Handler_Exit:
On Error Resume Next
Exit Function
Error_Handler:
Resume Error_Handler_Exit
End Function
测试
Sub test()
msg = "出现 " & 统计字符串出现次数("大家好,我是笨笨,笨笨的笨,笨笨的笨,谢谢!", "笨") & " 次"
MsgBox msg, vbOKOnly + vbInformation, "统计出现次数"
End Sub
Function 统计字符串出现次数(sourceStr As String, searchStr As String) As Long
On Error GoTo Error_Handler
统计字符串出现次数 = UBound(Split(sourceStr, searchStr))
Error_Handler_Exit:
On Error Resume Next
Exit Function
Error_Handler:
Resume Error_Handler_Exit
End Function