Sub test() Dim d As New Dictionary用户定义类型未定义 ”,怎么解决。以下是我要用的代码,麻烦修改
Subtest()DimdAsNewDictionaryDimd1AsNewDictionaryDimd2AsNewDictionaryDimd3AsNewDiction...
Sub test()
Dim d As New Dictionary
Dim d1 As New Dictionary
Dim d2 As New Dictionary
Dim d3 As New Dictionary
Dim d4 As New Dictionary
Dim r%, i%
Dim arr, brr
With Worksheets("销售明细")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a2:f" & r)
For i = 1 To UBound(arr)
d(arr(i, 1)) = d(arr(i, 1)) + arr(i, 6)
Next
End With
With Worksheets("入库明细")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a2:f" & r)
For i = 1 To UBound(arr)
d1(arr(i, 1)) = d1(arr(i, 1)) + arr(i, 6)
Next
End With
With Worksheets("退货")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a2:f" & r)
For i = 1 To UBound(arr)
d2(arr(i, 1)) = d2(arr(i, 1)) + arr(i, 6)
Next
End With
With Worksheets("生产领料")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a2:f" & r)
For i = 1 To UBound(arr)
d3(arr(i, 1)) = d3(arr(i, 1)) + arr(i, 6)
Next
End With
With Worksheets("生产领料 (辅材)")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a2:f" & r)
For i = 1 To UBound(arr)
d4(arr(i, 1)) = d4(arr(i, 1)) + arr(i, 6)
Next
End With
With Worksheets("动态库存")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a3:j" & r)
For i = 1 To UBound(arr)
If d.Exists(arr(i, 1)) Then
arr(i, 6) = d(arr(i, 1))
End If
If d1.Exists(arr(i, 1)) Then
arr(i, 7) = d1(arr(i, 1))
End If
If d2.Exists(arr(i, 1)) Then
arr(i, 8) = d2(arr(i, 1))
End If
If d3.Exists(arr(i, 1)) Then
arr(i, 9) = d3(arr(i, 1))
End If
If d4.Exists(arr(i, 1)) Then
arr(i, 10) = d4(arr(i, 1))
End If
Next
.Range("a3").Resize(UBound(arr), UBound(arr, 2)) = arr
End With
End Sub 展开
Dim d As New Dictionary
Dim d1 As New Dictionary
Dim d2 As New Dictionary
Dim d3 As New Dictionary
Dim d4 As New Dictionary
Dim r%, i%
Dim arr, brr
With Worksheets("销售明细")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a2:f" & r)
For i = 1 To UBound(arr)
d(arr(i, 1)) = d(arr(i, 1)) + arr(i, 6)
Next
End With
With Worksheets("入库明细")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a2:f" & r)
For i = 1 To UBound(arr)
d1(arr(i, 1)) = d1(arr(i, 1)) + arr(i, 6)
Next
End With
With Worksheets("退货")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a2:f" & r)
For i = 1 To UBound(arr)
d2(arr(i, 1)) = d2(arr(i, 1)) + arr(i, 6)
Next
End With
With Worksheets("生产领料")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a2:f" & r)
For i = 1 To UBound(arr)
d3(arr(i, 1)) = d3(arr(i, 1)) + arr(i, 6)
Next
End With
With Worksheets("生产领料 (辅材)")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a2:f" & r)
For i = 1 To UBound(arr)
d4(arr(i, 1)) = d4(arr(i, 1)) + arr(i, 6)
Next
End With
With Worksheets("动态库存")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a3:j" & r)
For i = 1 To UBound(arr)
If d.Exists(arr(i, 1)) Then
arr(i, 6) = d(arr(i, 1))
End If
If d1.Exists(arr(i, 1)) Then
arr(i, 7) = d1(arr(i, 1))
End If
If d2.Exists(arr(i, 1)) Then
arr(i, 8) = d2(arr(i, 1))
End If
If d3.Exists(arr(i, 1)) Then
arr(i, 9) = d3(arr(i, 1))
End If
If d4.Exists(arr(i, 1)) Then
arr(i, 10) = d4(arr(i, 1))
End If
Next
.Range("a3").Resize(UBound(arr), UBound(arr, 2)) = arr
End With
End Sub 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询