Solved

How to clear an autofilter in VBA

Posted on 2010-08-19
9
780 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

830 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