Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r1, r2, r3, i As Long
Dim rng As Range
r1 = [A65536].End(xlUp).Row
If Not Intersect(Range("H1:J1"), Target) Is Nothing Then
Range("A3:C" & r1).Copy
[G3].PasteSpecial Paste:=xlPasteValues
For i = 3 To r1
Set rng = Range(Cells(i, 7), Cells(i, 10))
If Cells(i, 7) <> Cells(1, 8).Value Or Month(Cells(i, 8)) <> Cells(1, 10).Value Then
rng.ClearContents
End If
Next
r2 = [I65536].End(xlUp).Row
Range("G3:I" & r2).Sort Key1:=[G3], Order1:=xlAscending
r3 = [I65536].End(xlUp).Row
Cells(r3 + 1, 9).Value = Application.WorksheetFunction.Sum(Range(Cells(3, 9), Cells(r3, 9)))
Cells(r3 + 1, 7).Value = "Tong Cong"
[H1].Select
End If
End Sub