VBA 未过滤范围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14426837/
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
VBA Unfilter range
提问by Sam
I am using this code:
我正在使用此代码:
Sheets("Sheet1").AutofilterMode = False
to unfilter the data in an Excel sheet using VBA (the point is to clear all the filters). This doesn't seem to always work, is there a better way?
使用 VBA 取消过滤 Excel 工作表中的数据(重点是清除所有过滤器)。这似乎并不总是有效,有没有更好的方法?
Thank you!
谢谢!
In case it helps, this table is linked from Sql Server (Data --> From other sources --> From Sql Server...) and it has a coloured design layout (table specific).
如果有帮助,此表是从 Sql Server 链接的(数据 --> 来自其他来源 --> 来自 Sql Server...),并且它具有彩色设计布局(特定于表)。
回答by A. Webb
Use Worksheets("Sheet1").ShowAllData
instead. See http://msdn.microsoft.com/en-us/library/office/bb178108%28v=office.12%29.aspx.
使用Worksheets("Sheet1").ShowAllData
来代替。请参阅http://msdn.microsoft.com/en-us/library/office/bb178108%28v=office.12%29.aspx。
回答by user9051866
The ShowAllData
will work only if your sheet has a filter, otherwise it will break. I found that you can create a function from this with On Error Resume Next
and it should work in all cases:
将ShowAllData
只会工作,如果你的表有一个过滤器,否则将中断。我发现你可以用On Error Resume Next
它创建一个函数,它应该适用于所有情况:
Sub ShowAllData()
On Error Resume Next
Worksheets("Sheet1").ShowAllData
End Sub
Then call function from your main sub:
然后从你的主子调用函数:
Sub Main()
ShowAllData
End Sub