Sub TEST()
Dim arr, brr, i&, j&, dic As Object
Set dic = CreateObject("Scripting.Dictionary")
arr = [A1].CurrentRegion
For i = 2 To UBound(arr)
brr = strExMatch(arr(i, 2))
If Join(brr) <> "" Then
For j = 1 To UBound(brr)
dic(brr(j)) = dic(brr(j)) + 1
Next j
End If
Next i
arr = Application.Transpose(Array(dic.keys, dic.items))
bsort arr, 1, UBound(arr), 1, UBound(arr, 2), 2, False
With Sheets(2)
.[A1].CurrentRegion.Offset(1).Clear
.[A2].Resize(UBound(arr), 2) = arr
.Activate
End With
Beep
End Sub
Function strExMatch(ByVal strTxt As String) As Variant
Dim regEx As Object, ar(), R&, aMatch, Matches
Set regEx = CreateObject("Vbscript.RegExp")
With regEx
.Global = True
.Pattern = "[\u4e00-\u9fa5]{2,4}"
End With
Set Matches = regEx.Execute(strTxt)
For Each aMatch In Matches
R = R + 1
ReDim Preserve ar(1 To R)
ar(R) = aMatch
Next
strExMatch = ar
End Function
Function bsort(arr, first, last, left, right, key, order)
Dim i, j, k, t
For i = first To last - 1
For j = first To last + first - 1 - i
If arr(j, key) <> arr(j + 1, key) Then
If arr(j, key) < arr(j + 1, key) Xor order Then
For k = left To right
t = arr(j, k): arr(j, k) = arr(j + 1, k): arr(j + 1, k) = t
Next
End If
End If
Next j, i
End Function
|