|
字典嵌套,“分而治之”,能快不少。
类似香川女侠的 二分法,可惜原理我不太懂。
Sub gg()
Dim dic, arr1, x&, s$, T As Double
T = Timer
Set dic = CreateObject("Scripting.Dictionary")
arr1 = Range("A1").CurrentRegion
Cells(2, 6) = Format(Timer - T, "0.0000s") '建立数组时间
For x = 1 To UBound(arr1, 1)
s = Mid(arr1(x, 1), 1, 1)
If Not dic.exists(s) Then
Set dic(s) = CreateObject("Scripting.Dictionary")
End If
dic(s)(arr1(x, 1)) = ""
Next
Cells(3, 6) = Format(Timer - T, "0.0000s") '添加KEY时间
sa = dic.items ' 可查看嵌套字典的详细情况
End Sub
生成数据,用数组,可秒杀:
Sub ff()
Dim T As Double, ar(1 To 999999, 1 To 1), i
Application.ScreenUpdating = False
T = Timer
For i = 1 To 999999
ar(i, 1) = i
Next
[a1].Resize(UBound(ar)) = ar
Cells(1, 6) = Format(Timer - T, "0.0000s") '数据生成时间
Application.ScreenUpdating = True
End Sub
|
|