Solved

How to clear an autofilter in VBA

Posted on 2010-08-19
9
744 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
Comment Utility
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.AutoFilterMode = False
End If
0
 
LVL 58

Expert Comment

by:cyberkiwi
Comment Utility
Replace ActiveSheet with Sheets("sheetname")...
0
 

Author Comment

by:JamesCbury
Comment Utility
thanks, that works to turn off the autofilters, but I'm just looking to reset them; essentially clicking 'select all' in each column.
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 250 total points
Comment Utility
If ActiveSheet.FilterMode Then
    ActiveSheet.ShowAllData
End If
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 45

Expert Comment

by:patrickab
Comment Utility
Try,

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

Author Closing Comment

by:JamesCbury
Comment Utility
perfect, thanks
0
 

Author Comment

by:JamesCbury
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now