vba 范围类的自动过滤方法失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14827833/
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
autofilter method of range class failed
提问by user2002592
ActiveSheet.Range("a1:b1").AutoFilter
ActiveSheet.Range("a1:b1").AutoFilter
the above code works fine but sometimes gives error 'autofilter method of range class failed'. my intention is to enable filtering for some columns without any criteria. is there any better way?
上面的代码工作正常,但有时会给出错误“范围类的自动过滤方法失败”。我的目的是在没有任何条件的情况下启用对某些列的过滤。有没有更好的方法?
回答by Jerry Beaucaire
As a rule I always turn off all prior filters, just in case.
作为一项规则,我总是关闭所有先前的过滤器,以防万一。
ActiveSheet.AutoFilterMode = False 'turn off prior filters
ActiveSheet.Range("A1:B1").AutoFilter 'turn on new clean filter