VBA Unfilter range

会有一股神秘感。 提交于 2019-12-30 09:03:14

问题


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?

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).


回答1:


Use Worksheets("Sheet1").ShowAllData instead. See http://msdn.microsoft.com/en-us/library/office/bb178108%28v=office.12%29.aspx.




回答2:


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:

Sub ShowAllData()
On Error Resume Next
Worksheets("Sheet1").ShowAllData

End Sub

Then call function from your main sub:

Sub Main()

ShowAllData

End Sub


来源:https://stackoverflow.com/questions/14426837/vba-unfilter-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!