Auto filter 1004 Error

BrizzleC

New Member
Joined
Mar 10, 2015
Messages
25
I am trying to filter and sort the Top 10 values in my spreadsheet but it keeps throwing up the '1004 Autofilter method of Range class failed' error, with the third line being highlighted.

My code is:

Code:
Range("B9:CS50").Select
Selection.Autofilter
Selection.Autofilter Field:=53, Criteria1="10", Operator:=xlTop10Items
Range("B10:CS50").Sort Key1:=Range("AW10"), Order:=xlDescending, Header _
   :=xlGuess, OrderCustom:=1, MatchCase:=False, Oreientation:=xlTopToBottom _
   , DataOption1:=xlSortNormal


The column being filtered and sorted contains £values but some are #N/A - will this be what is affecting the code?
If so, how do I get around this?

Many Thanks
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
is
Selection.Autofilter turning on the visible filter buttons
 
Upvote 0

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
what does doing it twice in a row do to it
 
Upvote 0

BrizzleC

New Member
Joined
Mar 10, 2015
Messages
25
ADVERTISEMENT
It stops on the second one, so I don't know.
I removed the first bit of code, so took out the repetition, and it still stops at the same line of code.
Have also tried to manually do a top 10 filter and it won't filter anything, although it will do a greater than and less than filter etc.
 
Upvote 0

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False

will turn off the filter if it is on

then when you issue the autofilter it isn't toggled

my system highlights an error with

Selection.Autofilter Field:=53, Criteria1="10", Operator:=xlTop10Items

maybe record it again and see if there was something missed
 
Upvote 0

BrizzleC

New Member
Joined
Mar 10, 2015
Messages
25
I already have that line of code at the start, which removes the filtering before I reapply.

As I've said, I am unable to manually "Top 10" the list so cannot record the MACRO exactly so I did it on another column which worked and just changed the field value to the correct one.

Just thinking that the #N/A cells are stopping the filter from working so I have used another column "3" to filter those elements out but still the Top10 filter on "53" won't work, vba or manually. Help?!
 
Upvote 0

Forum statistics

Threads
1,195,619
Messages
6,010,736
Members
441,567
Latest member
Flitbee

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
Top