How to auto-refresh an Excel auto-filter when data is changed?
Exchanging the code with this seems to do the trick as well (at least in Excel 2010):
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.AutoFilter.ApplyFilter
End Sub
I found that when I worked with tables, this didn't work. The filter was not on the sheet but on the table. this code did the trick
Private Sub Worksheet_Change(ByVal Target As Range)
With ActiveWorkbook.Worksheets("Sheet1").ListObjects("Table1")
.AutoFilter.ApplyFilter
End With
End Sub
I found the information here: http://www.jkp-ads.com/articles/Excel2007TablesVBA.asp
Just to consolidate the answer(s):
Sorin says:
Right click on your sheet name, choose "View Code" and paste the code below. After pasting, click the Excel icon below "File" at the top left, or type Alt-F11, to return to the spreadsheet view.
This will enable auto-refresh. Do not forget to save the file in a format with macro support lie .xlsm.
And Chris used this code (which I just did in 2010):
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.AutoFilter.ApplyFilter
End Sub
If you don't expand the post, you only see the long answer! ;)