Try below code ...
Sub Test()
Dim Lc As Long, Lr As Long, Rg As Range, j$
Set Rg = Sheet2.[A1:A2]
Rg = [{"Flag";1}]
With Sheet1
Lc = .Cells(1, Columns.Count).End(1).Column + 1
Lr = .Cells(Rows.Count, 1).End(3).Row
.Cells(1, Lc).Resize(Lr) = Evaluate("if(now()-3<" & .[B1].Resize(Lr).Address(, , , True) _
& "+" & .[C1].Resize(Lr).Address(, , , True) & ",1,"""")")
j = Split(.Cells(1, Columns.Count).End(1).Address, "$")(1)
.Cells(1, Lc + 1).Resize(Lr).Formula = "=SUMIF(A:A,A1," & j & ":" & j & ")"
.Cells(1, Lc + 1) = "Flag"
.[A1].CurrentRegion.AdvancedFilter 2, Rg, Sheet2.[F11:H11]
.Cells(1, Lc).Resize(Lr, 2).ClearContents
End With
Rg.ClearContents
End Sub
Bookmarks