|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("库存")
- rq = .Range("w2:x2")
- .Range("a3:t" & .Rows.Count).ClearContents
- End With
- ls = 20
- With Worksheets("原始数据")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:i" & r)
- ReDim brr(1 To UBound(arr), 1 To ls)
- For i = 1 To UBound(arr)
- For j = 1 To 7
- brr(i, j) = arr(i, j)
- Next
- brr(i, 8) = brr(i, 6) * brr(i, 7)
- brr(i, 19) = arr(i, 8)
- brr(i, 20) = arr(i, 9)
- d(brr(i, 2)) = i
- Next
- End With
- With Worksheets("收入")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- arr = .Range("a2:l" & r)
- For i = 1 To UBound(arr)
- If arr(i, 12) >= rq(1, 1) And arr(i, 12) <= rq(1, 2) Then
- If d.exists(arr(i, 2)) Then
- m = d(arr(i, 2))
- brr(m, 9) = brr(m, 9) + arr(i, 6)
- brr(m, 10) = brr(m, 10) + arr(i, 8)
- End If
- End If
- Next
- End With
- With Worksheets("发出")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- arr = .Range("a2:o" & r)
- For i = 1 To UBound(arr)
- If arr(i, 11) >= rq(1, 1) And arr(i, 11) <= rq(1, 2) Then
- If d.exists(arr(i, 2)) Then
- m = d(arr(i, 2))
- brr(m, 11) = brr(m, 11) + arr(i, 6)
- brr(m, 12) = brr(m, 12) + arr(i, 8)
- End If
- End If
- Next
- End With
- With Worksheets("退料")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- arr = .Range("a2:n" & r)
- For i = 1 To UBound(arr)
- If arr(i, 13) >= rq(1, 1) And arr(i, 13) <= rq(1, 2) Then
- If d.exists(arr(i, 2)) Then
- m = d(arr(i, 2))
- brr(m, 13) = brr(m, 13) + arr(i, 6)
- brr(m, 14) = brr(m, 14) + arr(i, 8)
- End If
- End If
- Next
- End With
- With Worksheets("退库")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- arr = .Range("a2:l" & r)
- For i = 1 To UBound(arr)
- If arr(i, 10) >= rq(1, 1) And arr(i, 10) <= rq(1, 2) Then
- If d.exists(arr(i, 2)) Then
- m = d(arr(i, 2))
- brr(m, 15) = brr(m, 15) + arr(i, 6)
- brr(m, 16) = brr(m, 16) + arr(i, 8)
- End If
- End If
- Next
- End With
- For i = 1 To UBound(brr)
- brr(i, 17) = brr(i, 6) + brr(i, 9) - brr(i, 11) + brr(i, 13) + brr(i, 15)
- brr(i, 18) = brr(i, 8) + brr(i, 10) - brr(i, 12) - brr(i, 14) - brr(i, 16)
- Next
- With Worksheets("库存")
- .Range("a3").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
|