Run Time Error '1004': Select Method of Worksheet class failed

KateP

New Member
Joined
Apr 18, 2017
Messages
3
Hi, I'm having trouble with this error that appears whenever I try to run macros.

Code:
Sub Filter()
   Sheets("Combination").Select
   Range("A4:AJ598").AutoFilter

   ActiveSheet.Range("$A$4:$AJ$598").AutoFilter Field:=1, Criteria1:="Y"
   ActiveSheet.AutoFilter.Range.Copy
   Sheets("Model").Select
   Range("A4").Select
   ActiveSheet.Paste
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try it this way...


Code:
Sub Filter()
   With Sheets("Combination")
       .Range("A4:AJ598").AutoFilter
       .Range("$A$4:$AJ$598").AutoFilter Field:=1, Criteria1:="Y"
       .AutoFilter.Range.Copy Sheets("Model").Range("A4")
   End With
End Sub
 
Upvote 0
Thank you so much Michael M! :)

This works fine although, I've tried replacing the .Select with .Activate.
and that works too. Would it be fine to do this instead With Sheets?


Regards,
KateP
 
Upvote 0
Yes, but why....you don't need to Select OR Activate a sheet to work with it !!
Using With sheets is much faster !!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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