Option Explicit
Sub Macro1()
Dim lngLastRow As Long
Dim rngFiltered As Range
Dim wsSource As Worksheet
Dim wsOutput As Worksheet
Application.ScreenUpdating = False
Set wsSource = Sheets("Sheet1") 'Sheet name containing the data. Change to suit.
Set wsOutput = Sheets("Sheet2") 'Sheet name for filtered data to be outputted to. Change to suit.
ActiveSheet.AutoFilterMode = False 'Remove all filters
'Ensure there's at least one row with a 'X' and a 'Y' in columns A and B
If Evaluate("COUNTIF('" & wsSource.Name & "'!A:A,""X"")") + Evaluate("COUNTIF('" & wsSource.Name & "'!B:B,""Y"")") = 0 Then
MsgBox "There are no rows with a X and Y in columns A and B!!", vbExclamation
Exit Sub
End If
lngLastRow = wsSource.Range("A:B").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
With wsSource.Range("$A$1:$B$" & lngLastRow)
.AutoFilter Field:=1, Criteria1:="X"
.AutoFilter Field:=2, Criteria1:="Y"
Set rngFiltered = .SpecialCells(xlCellTypeVisible)
If Not rngFiltered Is Nothing Then
rngFiltered.Copy Destination:=wsOutput.Range("A1")
End If
.AutoFilter
End With
Application.ScreenUpdating = True
MsgBox "Records have now been copied.", vbInformation
End Sub