Error 1004: AutoFilter method of Range class failed

vaibhavdxt

New Member
Joined
Nov 27, 2016
Messages
6
I am using same code in three different functions and it's working fine with two of them but with third one it's giving me "Error 1004: AutoFilter method of Range class failed".

I have a long code and I am getting error in this part of the code: -

Code:-

Public Sub XYZ (fcstartdate As Long, finaldate As Long)

With Sheets("XYZ")
.Range("$A$1:$AB$860423").AutoFilter Field:=14, Operator:= _
xlFilterValues, Criteria1:=">=" & fcstartdate, Operator:=xlAnd, Criteria2:="<=" & finaldate

Selection.SpecialCells(xlCellTypeVisible).Select
End With

End Sub

Please tell me what I should do to correct it.

I have checked that sheet is NOT protected and there is no merged rows. I also checked the number of rows in the sheet by recording macro which tells me there are 860423 though I see 67423 rows only.

Also when I ran the code with both figures (860423 and 67423), it gave me the same error.

Thanks in advance.

Regards
 
Thanks MARK858.

Yes I understand what Sektor is trying to say and I will change that in my code. But it is unbelievable to me as my code for other two functions runs without any problem. I am using those two functions from two months in my code. Today I added two more function, just by copying the code and changing the names and it is showing me error.
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
And changing the relevant part of the code to the code I posted gave you what?

But it is unbelievable to me

from the Autofilter method on MSDN...
The criteria (a string; for example, "101"). Use "=" to find blank fields, or use "<>" to find nonblank fields. If this argument is omitted, the criteria is All. If Operator is xlTop10Items, Criteria1 specifies the number of items (for example, "10").
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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