[B:B].Clear: [J1] = ""
xRow = 10
arr = [A1].Resize(xRow)
Brr = [C1].Resize(xRow)
Set xd = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(Brr)
xd(Brr(i, 1)) = 0
Next
k = xd.keys
t = xd.items
For i = 1 To UBound(arr)
For j = 0 To UBound(k)
If InStr(k(j), arr(i, 1)) Then t(i - 1) = t(i - 1) + 1
Next
Next
[B1].Resize(xRow) = Application.Transpose(t)
End Sub作者: PKKO 時間: 2015-9-16 19:57
Public Const R = 1000
Sub 取數3()
Dim i&, j&, Arr, Brr, Drr, T, SS, xD, xD1, TT$, M%, N%, Y$
'↑宣告變數
T = Timer
[B:B].ClearContents: [H3:H4] = ""
'↑清除結果欄舊資料
Arr = [A1].Resize(R): Brr = [B1].Resize(R): Drr = [D1].Resize(R)
'↑令(Arr,Brr,Drr)各是二維陣列帶入儲存格值
Set xD = CreateObject("Scripting.Dictionary")
Set xD1 = CreateObject("Scripting.Dictionary")
'↑令(xD,xD1)各是字典
For j = 1 To UBound(Drr)
'↑設順迴圈
TT = Drr(j, 1)
'↑令TT變數是 迴圈Drr陣列值
M = Len(TT)
'↑令M變數是 TT變數的字數
N = 1
'↑令N變數是 1
xD1.RemoveAll
'↑令清空 xD1字典
Do
'↑設條件迴圈
For i = 1 To M
'↑設順迴圈
Y = Mid(TT, N, i)
'↑令Y是 TT變數從 第1字開始取右側的字
If xD1(Y) = "" Then xD(Y) = xD(Y) + 1
'↑如果xD1字典裡沒有Y變數這key,就令xD字典納入,item累加1
xD1(Y) = 1
'↑令Y變數納入xD1字典裡,item是 1,讓xD1字典在下次清空前濾重複
Next i
N = N + 1: M = M - 1
'↑N.M變數做變化,以全部文字串組合逐次擷取
Loop Until M = 0
'↑執行到 最後一個字元
Next j
For i = 1 To UBound(Arr)
'↑設順迴圈
Y = Arr(i, 1): j = xD(Y)
'↑以Arr陣列值查xD字典回傳item值(該key出現過幾次)
Brr(i, 1) = j
'↑寫入Brr陣列
SS = SS + j
'↑累計次數
Next i
[B1].Resize(R) = Brr: [H3] = Timer - T: [H4] = SS
End Sub