Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Code to control auto filters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gordon - 20 Jan 2006 15:16 GMT
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
Zack Barresse - 20 Jan 2006 16:26 GMT
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

Signature

Regards,
Zack Barresse, aka firefytr, (GT = TFS FF Zack)
To email, remove the NO SPAM.  Please keep correspondence to the board, as
to benefit others.

>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
[quoted text clipped - 9 lines]
>
> Gordon
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.