Autofilter not working after code split

darekknox

New Member
Joined
Feb 19, 2015
Messages
31
Hi All,

I have a problem I am working on a huge macro and had to split some of it into separate macros due to the "Too large" error. The following is working when it's a part of the main code. But when I include it as a separate macro it crashes on the line where it refers to another sheet. Any ideas how to solve this?

Code:
   Sheets("ABCDE").Activate
    Rows("5:5").Select
 
    Selection.AutoFilter
    ActiveSheet.Range("$A$5:$M5").AutoFilter Field:=12, Criteria1:="<>"
    ActiveSheet.Range("$A$5:$M5").AutoFilter Field:=10, Criteria1:=Worksheets("johnny").Cells(i, 10).Value
     ActiveSheet.Range("$A$5:$M$792").AutoFilter Field:=6, Criteria1:=">0", _
        Operator:=xlAnd
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
What error and on which line? If its to do with the sheets then you probably need to qualify them such as Workbooks("Book3").Sheets("ABCDE") etc.
 
Upvote 0
Hi, thanks for quick reply.

It is Runtime Error '1004'. Application-defined or object efined error.

Line is

Code:
ActiveSheet.Range("$A$5:$M5").AutoFilter Field:=10, Criteria1:=Worksheets("johnny").Cells(i, 10).Value
 
Upvote 0

Forum statistics

Threads
1,214,874
Messages
6,122,036
Members
449,062
Latest member
mike575

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