excel|excel 自定义函数工具01统计字符在文本中出现的次数

'统计某字符串总共出现了几次,第一参数可以使用数组,单元格区域范围,第三参数默认为1时,表示不区分大小写,为0时严格区分大小写,,支持正则表达式


Function Count_X(ByVal Rng As Range, str As String, Optional i As Integer = 1)
【excel|excel 自定义函数工具01统计字符在文本中出现的次数】Application.Volatile
Dim rex As Object, met, k
Set rex = CreateObject("vbscript.regexp")
For Each R In Rng
With rex
.Global = True
.Pattern = str
.IgnoreCase = i
Set met = .Execute(R)
End With
k = k + met.Count
Next R
Count_X = k
End Function

    推荐阅读