Sub 汇总()
Set d = CreateObject("scripting.dictionary")
Sheet1.Range("c4:bd" & Sheet1.[a65536].End(3).Row) = ""
arr = Sheet2.UsedRange
For i = 2 To UBound(arr)
For j = 4 To 7
s = arr(i, 2) & arr(i, 3) & Val(Mid(arr(i, 1), 7, 2)) & "月" & arr(1, j)
p = arr(i, 2) & arr(i, 3) & arr(1, j)
If arr(i, 1) <> "" Then d(s) = d(s) + arr(i, j): d(p) = d(p) + arr(i, j)
Next: Next
For i = 4 To Sheet1.[a65536].End(3).Row
For j = 9 To Sheet1.[iv3].End(1).Column Step 4
For k = 0 To 3
Cells(i, j + k) = d(Cells(i, 1) & Cells(i, 2) & Cells(2, j) & Cells(3, j + k))
Cells(i, 3) = d(Cells(i, 1) & Cells(i, 2) & "计划")
Cells(i, 4) = d(Cells(i, 1) & Cells(i, 2) & "投产")
Cells(i, 6) = d(Cells(i, 1) & Cells(i, 2) & "入库")
Cells(i, 7) = d(Cells(i, 1) & Cells(i, 2) & "销售")
Cells(i, 5) = d(Cells(i, 1) & Cells(i, 2) & "投产") - d(Cells(i, 1) & Cells(i, 2) & "入库")
Cells(i, 8) = d(Cells(i, 1) & Cells(i, 2) & "入库") - d(Cells(i, 1) & Cells(i, 2) & "销售")
Next: Next: Next
End Sub |