Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Unfilter range

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

like image 629
Sam Avatar asked Jan 20 '13 16:01

Sam


2 Answers

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

like image 74
A. Webb Avatar answered Sep 28 '22 19:09

A. Webb


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
like image 35
user9051866 Avatar answered Sep 28 '22 20:09

user9051866