Get AutoFilter Criteria for Top10 filters

ttt123

Board Regular
Joined
May 31, 2006
Messages
120
Office Version
  1. 365
Platform
  1. Windows
I would like to know how to determine the original criteria used when someone filters with a 'Top10' autofilter.

The set of filters called 'Top10' actually includes four different filter types Top10Items, Bottom10Items, Top10Percent, and Bottom10Percent. Note that the names for these filters is confusing since you can use any number as the criteria not just 10. So more appropriate names would be something like TopNItems. The criteria is applied to the full data set and is not dependent on other filters.

Normally when you have a filter, you can see what the original criteria is by checking the filter object using some code like ActiveSheet.AutoFilter.Filters(1).Criteria1

the problem I am having is that when using a 'Top10' filter, the Criteria1 property actually gets changed to a <= or >= condition based on the numbers in your column and it doesn't seem possible to determine what the original Criteria used. So for example, if you have the numbers 1 to 100 in a column and set a Top10Items filter with Criteria1=5, then when you check the filter object after creation, it will have the Criteria1 as >=96.

This information is definitely not in the Filter object, and as far as I can tell it is also not in the Range object for the header cell. Note that when you hover over the filter, you see a screen tip (that looks similar to a comment) that shows the original filter criteria, but I can't find where the text for that screen tip is stored in the Range or AutoFilter objects. Note that counting the number of filtered items will not work either since duplicates are treated in an odd manner and the same number of items can be shown for different Top10Percent filters based on the rounding.

Does anyone know how to retrieve the original criteria for such a filter? I need to know it so that I can apply it programatically to a table on another worksheet. The problem is described in more detail here in the section entitled 'Discovery #4: Top 10 Settings Are Weird': http://yoursumbuddy.com/autofilter-vba-operator-parameters/
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

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