Private Sub Worksheet_Change(ByVal Target As Range)
Dim iR
If Target.Address = "$D$1" Or Target.Address = "$D$3" Or Target.Address = "$D$4" Then
iR = Sheet1.[A65536].End(3).Row
Sheet2.[F9].FormulaR1C1 = _
"=SUMPRODUCT(--(Sheet2!R3C4<=Sheet1!R2C1:R" & iR & "C1),--(Sheet2!R4C4>=Sheet1!R2C1:R" & iR & "C1),--(Sheet1!R2C4:R" & iR & "C4=Sheet2!R1C4),Sheet1!R2C7:R" & iR & "C7)"
Sheet2.[g9].FormulaR1C1 = _
"=SUMPRODUCT(--(Sheet2!R3C4<=Sheet1!R2C1:R" & iR & "C1),--(Sheet2!R4C4>=Sheet1!R2C1:R" & iR & "C1),--(Sheet1!R2C4:R" & iR & "C4=Sheet2!R1C4),Sheet1!R2C8:R" & iR & "C8)"
Sheet2.[F9:G9].Value = Sheet2.[F9:G9].Value
End If
End Sub