Solved

How to clear an autofilter in VBA

Posted on 2010-08-19
9
769 Views
Last Modified: 2012-06-11
Hi Experts, this should be an easy question, but I can't seem to find an answer.  I need a line or two of code that will clear all the autofilters in a given worksheet.  I have a sheet for which I refresh data on a regular basis, but if I have any filters set (which I often do) it screws up my refresh.  I can toggle the auto filters off then back on - but this seems kind of kludgy.

-Thanks,
0
Comment
Question by:JamesCbury
  • 4
  • 4
9 Comments
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33480103
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.AutoFilterMode = False
End If
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33480109
Replace ActiveSheet with Sheets("sheetname")...
0
 

Author Comment

by:JamesCbury
ID: 33480185
thanks, that works to turn off the autofilters, but I'm just looking to reset them; essentially clicking 'select all' in each column.
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 58

Accepted Solution

by:
cyberkiwi earned 250 total points
ID: 33480253
If ActiveSheet.FilterMode Then
    ActiveSheet.ShowAllData
End If
0
 
LVL 45

Expert Comment

by:patrickab
ID: 33480323
Try,

Sub see_all()
    Selection.AutoFilter Field:=1
End Sub
0
 

Author Closing Comment

by:JamesCbury
ID: 33480335
perfect, thanks
0
 

Author Comment

by:JamesCbury
ID: 33480371
Actually... this throws an error in the event that there are no filters set.  anyway around this other than an error handler?
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33480417
It works ok in Excel 2007 with or without filters, but you could try this variant:

If ActiveSheet.AutoFilterMode = True Then
    ActiveSheet.ShowAllData
End If
0
 

Author Comment

by:JamesCbury
ID: 33480534
sorry, I should have clarified.  It's throwing an error when I have autofilters on, but nothing is filtered (I get this it I try to run the sub two times in a row - the first time shows all, the second time throws an error).
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question