|
楼主 |
发表于 2013-11-22 11:01
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
学习记录:利用集合进行排序,不稳定排序
Sub test0() '生成测试数据
Dim ar(1 To 20000, 1 To 1)
For i = 1 To 20000
t = Int(16384 * Rnd() + 1)
ar(i, 1) = Split(Cells(t).Address, "$")(1)
Next
[a1:a20000] = ar
End Sub
Sub test1() '利用集合排序,不稳定。计时不含读、写单元格时间
Dim c As New Collection, ar()
ar = [a1:a20000].Value
ttt = Timer
For i = 1 To 20000
For Each t In c
If t >= ar(i, 1) Then Exit For
Next
If t = Empty Then
c.Add ar(i, 1), "|" & ar(i, 1)
Else
If t <> ar(i, 1) Then
c.Add ar(i, 1), "|" & ar(i, 1), before:="|" & t
Else
i2 = i2% + 1
c.Add ar(i, 1), "|" & i2 & ar(i, 1), after:="|" & ar(i, 1)
End If
End If
Next
i = 0
For Each t In c
i = i + 1
ar(i, 1) = t
Next
[b1] = Timer - ttt
[c1:c20000] = ar
End Sub
|
|