|
doitbest 发表于 2012-6-24 08:21
谢谢老师鼓励!!对两个代码进行了测试,结果相差无几。用6万条数据测试,3楼用时3.141秒,5楼用时3.156秒, ...
谢谢测试,如果速度没有提高就没有实际意义
请楼主用大数据测试下面两个程序:
- Public Sub sumif1() '6个字典
- Dim ar, br(), i, cr, dr, er, tt
- tt = Timer
- Dim d1 As Object, d2 As Object, d3 As Object, d4 As Object, d5 As Object, d6 As Object
- Set d1 = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- Set d3 = CreateObject("Scripting.Dictionary")
- Set d4 = CreateObject("Scripting.Dictionary")
- Set d5 = CreateObject("Scripting.Dictionary")
- Set d6 = CreateObject("Scripting.Dictionary")
- ar = Range([b6], [b6].End(4))
- ReDim br(1 To UBound(ar), 1 To 5)
- cr = Sheets("数据库.在途量").Range("e4:j" & Sheets("数据库.在途量").[j65536].End(3).Row)
- dr = Sheets("数据库.IQC在检").Range("a4:c" & Sheets("数据库.IQC在检").[c65536].End(3).Row)
- er = Sheets("数据库.森田总表").Range("c4:s" & Sheets("数据库.森田总表").[s65536].End(3).Row)
- For i = 1 To UBound(cr)
- If Not d1.exists(cr(i, 1)) Then
- d1(cr(i, 1)) = cr(i, 6)
- Else
- d1(cr(i, 1)) = d1(cr(i, 1)) + cr(i, 6)
- End If
- Next
- For i = 1 To UBound(dr)
- d2(dr(i, 1)) = dr(i, 3)
- Next
- For i = 1 To UBound(er)
- If Not d3.exists(er(i, 1)) Then d3(er(i, 1)) = er(i, 12)
- If Not d4.exists(er(i, 1)) Then d4(er(i, 1)) = er(i, 17)
- If Not d5.exists(er(i, 1)) Then d5(er(i, 1)) = er(i, 14)
- d6(er(i, 1)) = er(i, 5)
- Next
- For i = 1 To UBound(ar)
- If Not d1.exists(ar(i, 1)) Then
- br(i, 1) = 0
- Else
- br(i, 1) = d1(ar(i, 1))
- End If
- If d2.exists(ar(i, 1)) Then br(i, 2) = d2(ar(i, 1)) Else br(i, 2) = 0
- If d3.exists(ar(i, 1)) Then br(i, 3) = d3(ar(i, 1)) Else br(i, 3) = 0
- If d4.exists(ar(i, 1)) Then br(i, 4) = d4(ar(i, 1))
- If d5.exists(ar(i, 1)) Then br(i, 5) = d5(ar(i, 1))
- ar(i, 1) = d6(ar(i, 1))
- Next
- [j6].Resize(UBound(ar), 5) = br
- [e6].Resize(i - 1) = ar
- Set d1 = Nothing
- Set d2 = Nothing
- Set d3 = Nothing
- Set d4 = Nothing
- Set d5 = Nothing
- MsgBox Timer - tt
- End Sub
复制代码
- Sub Macro1() '1个字典
- Dim ar, br(), i&, j&, cr, dr, er, tt
- tt = Timer
- Dim d As Object
- Set d = CreateObject("Scripting.Dictionary")
- ar = Range([b6], [b6].End(4))
- ReDim br(1 To UBound(ar), 1 To 5)
- cr = Sheets("数据库.在途量").Range("e4:j" & Sheets("数据库.在途量").[j65536].End(3).Row)
- dr = Sheets("数据库.IQC在检").Range("a4:c" & Sheets("数据库.IQC在检").[c65536].End(3).Row)
- er = Sheets("数据库.森田总表").Range("c4:s" & Sheets("数据库.森田总表").[s65536].End(3).Row)
- For i = 1 To UBound(cr)
- d(cr(i, 1)) = d(cr(i, 1)) + cr(i, 6)
- Next
- For i = 1 To UBound(dr)
- d("A" & dr(i, 1)) = dr(i, 3)
- Next
- For i = 1 To UBound(er)
- If Not d.exists("B" & er(i, 1)) Then d("B" & er(i, 1)) = er(i, 12)
- If Not d.exists("C" & er(i, 1)) Then d("C" & er(i, 1)) = er(i, 17)
- If Not d.exists("D" & er(i, 1)) Then d("D" & er(i, 1)) = er(i, 14)
- d("E" & er(i, 1)) = er(i, 5)
- Next
- For i = 1 To UBound(ar)
- If d.exists(ar(i, 1)) Then br(i, 1) = d(ar(i, 1)) Else br(i, 1) = 0
- If d.exists("A" & ar(i, 1)) Then br(i, 2) = d("A" & ar(i, 1)) Else br(i, 2) = 0
- If d.exists("B" & ar(i, 1)) Then br(i, 3) = d("B" & ar(i, 1)) Else br(i, 3) = 0
- br(i, 4) = d("C" & ar(i, 1))
- br(i, 5) = d("D" & ar(i, 1))
- ar(i, 1) = d("E" & ar(i, 1))
- Next
- [j6].Resize(i - 1, 5) = br
- [e6].Resize(i - 1) = ar
- MsgBox Timer - tt
- End Sub
复制代码
|
|