Sub Ex()
Dim rng As Range, ctn As Range
Dim typ As String, amt As Double
[A23:F35].Clear
typ = "": amt = 0
[E53:E60] = 0
Set ctn = [A23]
For Each rng In Range("C3", [C3].End(xlDown))
If rng = [C20] Then
If typ = "" Then typ = rng.Offset(, 1)
ctn = rng.Offset(, -2) ' 日期
ctn.Offset(, 1) = rng.Offset(, 3) ' 品名
ctn.Offset(, 2) = rng.Offset(, 5) ' 件數
ctn.Offset(, 3) = rng.Offset(, 6) ' 重量
ctn.Offset(, 4) = rng.Offset(, 7) ' 單價
ctn.Offset(, 5) = rng.Offset(, 8) ' 金額
amt = amt + ctn.Offset(, 5).Value
Set ctn = ctn.Offset(1)
End If
Next
[E53] = amt
[E54] = amt * IIf(typ = "蔬菜", [J24].Value, [J25].Value)
[E55] = amt * IIf(typ = "蔬菜", [J27].Value, [J28].Value)
[E56] = amt * IIf(typ = "蔬菜", [J32].Value, [J33].Value)
[E59] = amt * IIf(typ = "蔬菜", [J36].Value, [J37].Value)