prezftb09

New Member
Joined
Mar 5, 2018
Messages
8
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:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi & welcome to MrExcel
How about
Code:
On Error Resume Next
ws.Range("Y2:AO" & data_end_row_number).SpecialCells(xlCellTypeVisible).copy
On error goto 0
 
Upvote 0
Thank you so much. i knew it was something as simple as adding and error fix but new to this and couldnt figure it out.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,982
Members
449,201
Latest member
Lunzwe73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top