I have the below code, it looks for a filter criteria in column V and then it will take filtered criteria and paste in a separate. However, sometimes there might not be any data filtered and thus get the "No cells were found" error. Any assistance?
Code:
Sub copy()
'source worksheet
Dim ws As Worksheet
Set ws = Application.Worksheets("Data") ' set you source worksheet here
Dim data_end_row_number As Integer
data_end_row_number = ws.Range("A1").End(xlDown).Row
'enable filter
ws.Range("A1:AO1").AutoFilter Field:=22, Criteria1:="YES", VisibleDropDown:=True
ws.Range("Y2:AO" & data_end_row_number).SpecialCells(xlCellTypeVisible).copy
Sheets("Delete").Activate
'Select the target range
Range("A2").Select
'Paste in the target destination
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
Last edited by a moderator: