Inconsistent Autofilter Runtime Error

Status
Not open for further replies.

MAM8433

New Member
Joined
May 18, 2011
Messages
44
How do I get this code to run consistently without error?

I recently received MrExcel help for the code below. At first it didn’t work; I was getting a runtime error. Then on Friday it did work (!!) without any edits in this code, and today I’m again seeing “Runtime error 1004: Autofilter method range class failure” in the second line of code.

With Worksheets("Provider").Range(Cells(8, 1), Cells(intLastRowN, intLastCol))
.AutoFilter Field:=intBCOCol, Criteria1:="Y"
.AutoFilter Field:=intBCOExcCol, Criteria1:="OUT"
End With

Nothing is random in VBA.

On the first line, when I hover over the word “Cells” in Cells(intLastRowN, intLastCol): it shows “Cells(intLastRowN, intLastCol)=Error 2042” even though the content of intLastRowN and intLastCol are correct (2477 and 26, respectively).

Is error 2042 the source of my trouble? I do have “N/As” in the intBCOExcCol column.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Duplicate Autofilter with Variables

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,575
Messages
6,125,631
Members
449,241
Latest member
NoniJ

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