Code to control auto filters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a column that I need auto filtering to the top ten values in say
column/range A10:A100. I'm looking for code to do this. the code should begin
with removing all filters and then re-instating them so they are back to an
unfiltered state. I don't want my users touching the filters, but more just
touching a macro button to execute the procedure. I asked this question
earlier today but the code came up as invalid in red.

Any help gratefully received.

Gordon
 
Hello Gordon,

You could use something like this ...

Option Explicit
Sub FilterTopTen()
'take off autofilter
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.Cells.AutoFilter
End If
'set new autofilter
Range("A10:A100").AutoFilter Field:=1, Criteria1:="10",
Operator:=xlTop10Items
' Range("A10:A100").AutoFilter Field:=1, Criteria1:="10",
Operator:=xlTop10Percent
End Sub

You didn't specify if you wanted top 10 items or percent. You have
either/or to choose from. Note this assumes the activesheet is the sheet
with the range you wish to filter.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top