Hello everyone,

My code below is to extract rows in sheet 1 to sheet 2 with the inefficient loop. The condition is to check if the date matches (as shown below).

Is it possible to use something like AutoFilter to improve the efficiency? Thanks.

Sub FindCopy()
    
    Dim lastrow As Long, i As Long, j As Long
    Dim dt As Date, lastmend As Date

    With Worksheets("Sheet1")
        lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
    
    With Worksheets("Sheet2")
        j = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
    End With

    Application.ScreenUpdating = False

    On Error Resume Next
    
    For i = 1 To lastrow
        With Worksheets("Sheet1")
            dt = .Cells(i, 1).Value
            lastmend = DateSerial(Year(dt), Month(dt), 0)
            If lastmend = Range("LastMEnd") Then
                .Rows(i).Copy
                Worksheets("Sheet2").Range("A" & j).PasteSpecial xlPasteValues
                j = j + 1
            End If
        End With
    Next i

End Sub