Sub ext()
Dim a As Range, i As Integer, c As Integer
Set dic = CreateObject("Scripting.Dictionary")
Set d = CreateObject("Scripting.Dictionary")
With Sheets("庫存")
i = 1
Do Until .Cells(1, i) = ""
myday = .Cells(1, i).Value
For Each a In .Range(.Cells(2, i), .Cells(.Rows.Count, i).End(xlUp))
ar = Array(a.Offset(, 3), a.Offset(, 4))
If IsEmpty(dic(a & d(Val(a)))) Then
dic(a & d(Val(a))) = ar
Else
dic(a & d(Val(a))) = Array(dic(a & d(Val(a)))(0) + ar(0), dic(a & d(Val(a)))(1) + ar(1))
End If
Next
For c = 2 To Worksheets.Count
With Sheets(c)
s = .Cells(2, .Columns.Count).End(xlToLeft).Column + 1