Option Explicit
Sub TEST()
Dim Brr, V, Z, i&, R&, 館$, 廠$
Sheets("館別及廠商").UsedRange.Offset(3).EntireRow.Delete
館 = [館別及廠商!C1]: 廠 = [館別及廠商!E1]: If 館 = "" Or 廠 = "" Then Exit Sub
Brr = Range([總表!L1], [總表!A65536].End(xlUp))
For i = 3 To UBound(Brr)
If Brr(i, 1) <> 館 Or Brr(i, 12) <> 廠 Then GoTo i01 Else R = R + 1
Brr(R, 1) = Brr(i, 2): Brr(R, 2) = Brr(i, 3): Brr(R, 3) = Brr(i, 4)
Brr(R, 4) = Val(Brr(i, 11)): Brr(R, 5) = Val(Brr(i, 10))
V = V + Brr(R, 4) * Brr(R, 5)
i01: Next
If R = 0 Then Exit Sub
With [館別及廠商!A4].Resize(R, 5)
.Value = Brr: .Item(0, 5) = "=總表!J2"
For i = 7 To 10: .Borders(i).Weight = 4: Next
.Item(.Count + 4) = "合計": .Item(.Count + 5) = V
.Item(.Count + 5).NumberFormatLocal = "G/通用格式""元"""
End With
End Sub作者: mdr0465 時間: 2024-3-4 22:23
Sub TEST()
Dim Brr, V, Z, i&, R&, 館$, 廠$
Sheets("館別及廠商").UsedRange.Offset(3).EntireRow.Delete
館 = [館別及廠商!C1]: 廠 = [館別及廠商!E1]: If 館 = "" Or 廠 = "" Then Exit Sub
Brr = Range([總表!L1], [總表!A65536].End(xlUp))
For i = 3 To UBound(Brr)
If Brr(i, 1) <> 館 Or Brr(i, 12) <> 廠 Then GoTo i01 Else R = R + 1
Brr(R, 1) = Brr(i, 2): Brr(R, 2) = Brr(i, 3): Brr(R, 3) = Brr(i, 4)
Brr(R, 4) = Val(Brr(i, 11)): Brr(R, 5) = Val(Brr(i, 10))
V = V + Brr(R, 4) * Brr(R, 5)
i01: Next
If R = 0 Then Exit Sub
With [館別及廠商!A4].Resize(R, 5)
.Value = Brr: .Item(0, 5) = "=總表!J2"
For i = 7 To 10: .Borders(i).Weight = 4: Next
.Item(.Count + 4) = "合計": .Item(.Count + 5) = V
.Item(.Count + 5).NumberFormatLocal = "G/通用格式""元"""
End With
End Sub