VBA Excel autofiltermode = false 不关闭自动过滤器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24864408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:27:50  来源:igfitidea点击:

VBA Excel autofiltermode = false not turning off autofilter

excelvbaexcel-vbaautofilter

提问by ghostracer34

Have used activesheet.autofiltermode = falseand

用过activesheet.autofiltermode = false

dim Myworksheet as worksheet
Myworksheet.autofiltermode = false

Neither removed autofilter I've use Myworksheet.ShowAllDatabeforehand as well. Using Office 2013 Professional Plus

也没有删除我Myworksheet.ShowAllData事先使用过的自动过滤器。使用 Office 2013 专业增强版

回答by Rory

For a table you need different syntax:

对于表,您需要不同的语法:

activesheet.listobjects(1).Autofilter.showalldata

to clear the filter, or:

清除过滤器,或:

activesheet.listobjects(1).ShowAutoFilter = False

if you don't want the dropdowns visible at all.

如果您根本不希望下拉菜单可见。

回答by M Dattoli

This finallyhelped me figure out how to ensure that an Excel table's AutoFilter is on and showing all data. My final code is this:

最终帮助我弄清楚如何确保 Excel 表的自动筛选器已打开并显示所有数据。我的最终代码是这样的:

If ActiveSheet.ListObjects(1).ShowAutoFilter Then
   ActiveSheet.ListObjects(1).AutoFilter.ShowAllData
Else
   ActiveSheet.ListObjects(1).ShowAutoFilter = True
End If