这个宏会提取所有10分钟内有3G,20分钟内有5G的1G线路。
Sub Macro2()
Dim lLastRow As Long, shtOrg As Worksheet, shtDest As Worksheet, rgLoop As Range
'turn off updates to speed up code execution
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
Set shtOrg = ActiveSheet
Set shtDest = Sheets.Add
lLastRow = shtOrg.Cells(Rows.Count, 1).End(xlUp).Row
shtOrg.Range("D2:D" & lLastRow).FormulaR1C1 = _
"=IF(RC[-2]=""1G"",IF(COUNTIFS(C[-3],"">="" &RC[-3],C[-3],""<=""&RC[-3]+10/1440,C[-2],""3G"")*COUNTIFS(C[-3],"">="" &RC[-3],C[-3],""<=""&RC[-3]+20/1440,C[-2],""5G"")>0,TRUE,""""),"""")"
shtOrg.Range("E2:E" & lLastRow).FormulaR1C1 = _
"=N(IF(RC[-3]=""3G"",COUNTIFS(C[-1],TRUE,C[-4],""<=""&RC[-4],C[-4],"">=""&RC[-4]-10/1440),IF(RC[-3]=""5G"",COUNTIFS(C[-1],TRUE,C[-4],""<=""&RC[-4],C[-4],"">=""&RC[-4]-20/1440),"""")))>0"
shtOrg.Range("A1:E" & lLastRow).AutoFilter field:=4, Criteria1:="TRUE"
shtOrg.Range("A1:C" & lLastRow).SpecialCells(xlCellTypeVisible).Copy shtDest.Cells(1, 1)
shtOrg.Range("A1:E" & lLastRow).AutoFilter
shtOrg.Range("A1:E" & lLastRow).AutoFilter field:=5, Criteria1:="TRUE"
shtOrg.Range("A2:C" & lLastRow).SpecialCells(xlCellTypeVisible).Copy shtDest.Cells(Rows.Count, 1).End(xlUp).Offset(1)
shtOrg.Columns("D:E").ClearContents
shtOrg.Range("A1:E" & lLastRow).AutoFilter
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End Sub