Clear filter from Table

2020-02-09 07:48发布

I'm trying to run a macro that replaces data in a table in Excel, when the data might initially be filtered.

The code should remove the filter first, then run the rest of the code.

I tried the "Autofilter" command, but then the normal filter option on the table's range weren't visible, and I had to manually create the filter option again (not a big deal to me, but other people use this file).

Is there a way to clear the filter WITHOUT removing filters from the table?

4条回答
该账号已被封号
2楼-- · 2020-02-09 08:24

For a Table, you can simply use the ShowAllData method of its Autofilter object:

activesheet.listobjects(1).autofilter.showalldata

Note this won't error even if there is no filter currently applied.

查看更多
老娘就宠你
3楼-- · 2020-02-09 08:24

I am finding that the "...ClearAllData" method fails.

Sneaky - not hugely elegant solution - that works by field (so cumbersome if you need to do the whole table), but easy if you just have one field (e.g. field 2 in my example) is to use the wildcard:

ActiveSheet.ListObjects(1).Range.AutoFilter Field:=2, Criteria1:="=*"
查看更多
女痞
4楼-- · 2020-02-09 08:26
ActiveSheet.ShowAllData

Or

Cells.AutoFilter
查看更多
Ridiculous、
5楼-- · 2020-02-09 08:47

Hi Guys use this "Worksheets("Sheet1").ListObjects(1).Range.AutoFilter = False" and please note if already filter applied it will remove filter on the other hand if filter not applied before it will apply the filter.

查看更多
登录 后发表回答