2013-07-09 45 views
3

是否有任何方法檢查工作表是否有任何過濾的數據(如果存在過濾的數據,則清除過濾器,否則什麼也不做)?我這裏有這樣的代碼,但我不知道該怎麼寫第二部分:過濾數據的VBA檢查表

Sub ProtectAll() 

Dim wSheet   As Worksheet 

For Each wSheet In Worksheets 

With wSheet 
If .AutoFilterMode Then 
      .ShowAllData 
      .Cells.Locked = True 
      .Cells.FormulaHidden = False 
      '.Range(wSheet.Cells(12, 1), wSheet.Cells(12, 18)).AutoFilter 
      '.Protect Password:=Pwd, AllowFiltering:=True 

ElseIf ??? Then 
End If 
End With 

Next wSheet 
End Sub 
+1

參見Excel幫助[谷歌的excel自動篩選](http://www.google.com/search?hl=en&q=msdn+excel+autofilter+property)和[MSDN的excel自動篩選](http://msdn.microsoft.com/en-us /library/office/ff834384.aspx) –

+1

@ d-stroyer謝謝你的建議。我發現重新應用過濾器可以做到這一點。 – atomoutside

回答

0

此代碼刪除所有自動篩選從ActiveSheet

ActiveSheet.Autofilter.Range.Autofilter 

之後,您可以重新設置過濾器(沒有選擇的標準)通過定義適當的範圍

ActiveSheet.Range("A1:B1").Autofilter