Sub 查找() Dim Dic As New Dictionary为什么会出现用户定义类型未定义的对话框 Dim Arr, dR_n&, i&, S$, Cnt& Dim Rng As Range Arr = Sheet3.Range("A3:E" & Sheet1.[a65536].End(xlUp).Row) '把订单明细的数据赋值给ARR Range("D3:H" & [d65536].End(xlUp).Row + 1).ClearContents For i = 1 To UBound(Arr) If Arr(i, 1) >= [A2] And Arr(i, 1) <= [C2] Then S = Arr(i, 3) If Not Dic.Exists(S) Then Dic(S) = Arr(i, 5) dR_n = [d65536].End(xlUp).Row + 1 Cells(dR_n, 4) = Arr(i, 2) Cells(dR_n, 5) = Arr(i, 3) Else Dic(S) = Dic(S) + Arr(i, 5) End If End If Next Arr = Sheet7.Range("A3:G" & Sheet2.[a65536].End(xlUp).Row) Set Rng = Range("D3:D" & [d65536].End(xlUp).Row) For i = 1 To UBound(Arr) If Arr(i, 1) >= [A2] And Arr(i, 1) <= [C2] Then S = Arr(i, 4) If Not Dic.Exists(S) Then dR_n = [d65536].End(xlUp).Row + 1 Cells(dR_n, 4) = Arr(i, 4) Cells(dR_n, 5) = Arr(i, 4) Cells(dR_n, 7) = Arr(i, 6) Set Rng = Range("D3:D" & [d65536].End(xlUp).Row) Else Cnt = Rng.Find(S).Row Cells(Cnt, 6) = Dic(S) Cells(Cnt, 7) = Cells(Cnt, 7) + Arr(i, 6) Cells(Cnt, 8) = Cells(Cnt, 7) - Dic(S) End If End If Next End Sub
把红色部份改成后期绑定: Dim d As Object Set d = CreateObject("Scripting.Dictionary") 或工具-引用-“microsoft scripting runtime”
|