2,463
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Public Function GetKeyCount(ByVal objRange As Range, ByVal objKey As Range) As Integer
Dim reg As Object
Set reg = CreateObject("vbscript.regexp")
reg.Global = True
reg.ignorecase = True
reg.Pattern = objKey.Value
Dim strInput As String
strInput = ""
Dim objSubRange As Range
For Each objSubRange In objRange
If objSubRange.Value <> "" Then
strInput = strInput & objSubRange.Value & vbCrLf
End If
Next
Dim colMatches As Object
Set colMatches = reg.Execute(strInput)
GetKeyCount = colMatches.Count
End Function