|
我的两个方法都比赵版的双字典方法快一些。- Sub kagawa_dic()
- tms = Timer
- Dim i%, j%, m&
-
- m = [a65536].End(3).Row
- arr = [b1].Resize(m, 4)
- ReDim brr(2 To m, 1 To 6)
-
- Set d1 = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- Set d3 = CreateObject("Scripting.Dictionary")
-
- For i = 2 To m
- d1(arr(i, 1)) = d1(arr(i, 1)) & ";" & i
- d2(arr(i, 3)) = d2(arr(i, 3)) & ";" & i
- d3(arr(i, 4)) = d3(arr(i, 4)) & ";" & i
- Next
-
- s = d1.items
- Set d1 = Nothing
- For i = 0 To UBound(s)
- t = Split(s(i), ";")
- n = UBound(t)
- If n > 1 Then
- For j = 1 To n
- brr(t(j), 1) = t(1)
- brr(t(j), 2) = n
- Next
- End If
- Next
-
- s = d2.items
- Set d2 = Nothing
- For i = 0 To UBound(s)
- t = Split(s(i), ";")
- n = UBound(t)
- If n > 1 Then
- For j = 1 To n
- brr(t(j), 3) = t(1)
- brr(t(j), 4) = n
- Next
- End If
- Next
-
- s = d3.items
- Set d3 = Nothing
- For i = 0 To UBound(s)
- t = Split(s(i), ";")
- n = UBound(t)
- If n > 1 Then
- For j = 1 To n
- brr(t(j), 5) = t(1)
- brr(t(j), 6) = n
- Next
- End If
- Next
-
- [k2].Resize(m - 1, 6) = brr
- ' MsgBox Format(Timer - tms, "0.0000s")
- End Sub
复制代码 这个字典方法速度最快。- Sub kagawa_Arr()
- tms = Timer
- Dim i%, j%, m&
-
- m = [a65536].End(3).Row
- arr = [b1].Resize(m)
- ReDim brr(2 To m, 3)
-
- Set d = CreateObject("Scripting.Dictionary")
- For i = 2 To m
- t = d(arr(i, 1))
- If t = "" Then
- brr(i, 2) = i
- d(arr(i, 1)) = i
- Else
- brr(i, 2) = t
- brr(t, 3) = brr(t, 3) + 1
- End If
- Next
- d.RemoveAll
-
- For i = 2 To m
- If brr(i, 2) <> "" Then
- If brr(brr(i, 2), 3) > 0 Then
- brr(i, 0) = brr(i, 2)
- brr(i, 1) = brr(brr(i, 2), 3) + 1
- End If
- End If
- Next
- [k2].Resize(m - 1, 2) = brr
-
- arr = [d1].Resize(m)
- ReDim brr(2 To m, 3)
-
- For i = 2 To m
- t = d(arr(i, 1))
- If t = "" Then
- brr(i, 2) = i
- d(arr(i, 1)) = i
- Else
- brr(i, 2) = t
- brr(t, 3) = brr(t, 3) + 1
- End If
- Next
- d.RemoveAll
-
- For i = 2 To m
- If brr(i, 2) <> "" Then
- If brr(brr(i, 2), 3) > 0 Then
- brr(i, 0) = brr(i, 2)
- brr(i, 1) = brr(brr(i, 2), 3) + 1
- End If
- End If
- Next
- [m2].Resize(m - 1, 2) = brr
-
- arr = [e1].Resize(m)
- ReDim brr(2 To m, 3)
-
- For i = 2 To m
- t = d(arr(i, 1))
- If t = "" Then
- brr(i, 2) = i
- d(arr(i, 1)) = i
- Else
- brr(i, 2) = t
- brr(t, 3) = brr(t, 3) + 1
- End If
- Next
- Set d = Nothing
-
- For i = 2 To m
- If brr(i, 2) <> "" Then
- If brr(brr(i, 2), 3) > 0 Then
- brr(i, 0) = brr(i, 2)
- brr(i, 1) = brr(brr(i, 2), 3) + 1
- End If
- End If
- Next
- [o2].Resize(m - 1, 2) = brr
-
- ' MsgBox Format(Timer - tms, "0.0000s")
- End Sub
复制代码 这个字典+数组方法要慢一些。 |
|