Option Explicit
Sub TEST()
Dim Brr, Z, i&, j%, R&, 起始日 As Date, 結束日 As Date, xR As Range
Set Z = CreateObject("Scripting.Dictionary")
[統計表!A1].CurrentRegion.Offset(1, 0).ClearContents
起始日 = [統計表!L2]: 結束日 = [統計表!L3]
Brr = Range([工作表1!I1], [工作表1!A65536].End(3))
For i = 2 To UBound(Brr)
If Brr(i, 7) < 起始日 Or Brr(i, 7) > 結束日 Then GoTo i01 Else R = R + 1
For j = 2 To 9: Brr(R, j - 1) = Brr(i, j): Next
Z(Brr(i, 5) & "/" & Brr(i, 6)) = Z(Brr(i, 5) & "/" & Brr(i, 6)) + Val(Brr(i, 4))
i01: Next
If R = 0 Then Exit Sub
With [統計表!A2].Resize(R, 8)
.Value = Brr
.Cells(.Count + 2) = "Total"
.Cells(.Count + 3) = "=SUM(" & .Columns(3).Address & ")"
Set xR = .Cells(.Count + 4)
End With
For i = 0 To Z.Count - 1: Brr(i + 1, 1) = Z.keys()(i): Brr(i + 1, 2) = Z.items()(i): Next
xR.Resize(Z.Count, 2) = Brr
End Sub作者: hcm19522 時間: 2023-12-27 16:45