Filters 物件 (Excel)Filters object (Excel)

Filter 物件的集合,代表自動篩選範圍中的所有篩選。A collection of Filter objects that represents all the filters in an autofiltered range.


使用AutoFilter物件的 [篩選] 屬性可傳回Filters集合。Use the Filters property of the AutoFilter object to return the Filters collection. 下列範例會建立一份清單,其中包含 Crew 工作表上自動篩選範圍中各項篩選的準則及運算子。The following example creates a list that contains the criteria and operators for the filters in the autofiltered range on the Crew worksheet.

Dim f As Filter 
Dim w As Worksheet 
Const ns As String = "Not set" 
Set w = Worksheets("Crew") 
Set w2 = Worksheets("FilterData") 
rw = 1 
For Each f In w.AutoFilter.Filters 
 If f.On Then 
 c1 = Right(f.Criteria1, Len(f.Criteria1) - 1) 
 If f.Operator Then 
 op = f.Operator 
 c2 = Right(f.Criteria2, Len(f.Criteria2) - 1) 
 op = ns 
 c2 = ns 
 End If 
 c1 = ns 
 op = ns 
 c2 = ns 
 End If 
 w2.Cells(rw, 1) = c1 
 w2.Cells(rw, 2) = op 
 w2.Cells(rw, 3) = c2 
 rw = rw + 1 

使用篩選器(索引),其中_index_是篩選器標題或索引編號,可以傳回單一的Filter物件。Use Filters (index), where index is the filter title or index number, to return a single Filter object. 下列範例會將變數設定為 Crew 工作表上篩選範圍中第一欄篩選的 On 屬性值。The following example sets a variable to the value of the On property of the filter for the first column in the filtered range on the Crew worksheet.

Set w = Worksheets("Crew") 
If w.AutoFilterMode Then 
 filterIsOn = w.AutoFilter.Filters(1).On 
End If


另請參閱See also

支援和意見反應Support and feedback

有關於 Office VBA 或這份文件的問題或意見反應嗎?Have questions or feedback about Office VBA or this documentation? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.