|
Sub 按钮1_Click()
Set sh = ActiveSheet
Application.ScreenUpdating = False
Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
arr = Sheets("入库").UsedRange
For j = 2 To UBound(arr)
d1(Format(arr(j, 1), "yyyy年m月") & "###" & arr(j, 2)) = d1(Format(arr(j, 1), "yyyy年m月") & "###" & arr(j, 2)) + arr(j, 3)
d2(Format(arr(j, 1), "yyyy年m月") & "###" & arr(j, 2)) = d2(Format(arr(j, 1), "yyyy年m月") & "###" & arr(j, 2)) + arr(j, 4)
Next j
sh.UsedRange.Offset(2).ClearContents
For j = 0 To d1.Count - 1
Cells(j + 3, 1).Resize(1, 2) = Split(d1.keys()(j), "###")
Cells(j + 3, 3) = d1.items()(j)
Cells(j + 3, 4) = d2.items()(j)
Next j
arr = Sheets("出库").UsedRange
d1.RemoveAll
d2.RemoveAll
For j = 2 To UBound(arr)
d1(Format(arr(j, 1), "yyyy年m月") & "###" & arr(j, 2)) = d1(Format(arr(j, 1), "yyyy年m月") & "###" & arr(j, 2)) + arr(j, 3)
d2(Format(arr(j, 1), "yyyy年m月") & "###" & arr(j, 2)) = d2(Format(arr(j, 1), "yyyy年m月") & "###" & arr(j, 2)) + arr(j, 4)
Next j
r = Cells(Rows.Count, 1).End(3).Row + 1
For j = 3 To Cells(Rows.Count, 1).End(3).Row
aa = Format(Cells(j, 1), "yyyy年m月") & "###" & Cells(j, 2)
If d1.exists(Format(Cells(j, 1), "yyyy年m月") & "###" & Cells(j, 2)) Then
Cells(j, 5) = d1(Format(Cells(j, 1), "yyyy年m月") & "###" & Cells(j, 2))
Cells(j, 6) = d2(Format(Cells(j, 1), "yyyy年m月") & "###" & Cells(j, 2))
End If
Next j
Application.ScreenUpdating = True
End Sub |
|