Range.AdvancedFilter 方法 (Excel)Range.AdvancedFilter method (Excel)

根據準則範圍,從清單中篩選或複製資料。Filters or copies data from a list based on a criteria range. 如果初始選擇為單一儲存格,則會使用儲存格的目前區域。If the initial selection is a single cell, that cell's current region is used.

語法Syntax

運算式AdvancedFilter(巨集指令CriteriaRangeCopyToRange唯一)expression.AdvancedFilter (Action, CriteriaRange, CopyToRange, Unique)

expression 代表 Range 物件的變數。expression A variable that represents a Range object.

參數Parameters

名稱Name 必要/選用Required/Optional 資料類型Data type 描述Description
ActionAction 必要Required XlFilterActionXlFilterAction XlFilterAction 的其中一個常數,指定是否要複製清單或在原有範圍顯示篩選結果。One of the constants of XlFilterAction specifying whether to make a copy or filter the list in place.
CriteriaRangeCriteriaRange 選用Optional VariantVariant 準則範圍。The criteria range. 如果省略此引數則無準則。If this argument is omitted, there are no criteria.
CopyToRangeCopyToRange 選用Optional VariantVariant 如果_Action_為xlFilterCopy所複製列目的地範圍。The destination range for the copied rows if Action is xlFilterCopy. 否則,會忽略此引數。Otherwise, this argument is ignored.
UniqueUnique 選用Optional VariantVariant 若為 True ,只篩選出唯一的記錄。True to filter unique records only. 若為 False ,篩選出所有符合準則的記錄。False to filter all records that meet the criteria. 預設值為 FalseThe default value is False.

傳回值Return value

VariantVariant

範例Example

本範例會篩選名為根據準則範圍名為準則的資料庫的資料庫。This example filters a database named Database based on a criteria range named Criteria.

Range("Database").AdvancedFilter _ 
 Action:=xlFilterInPlace, _ 
 CriteriaRange:=Range("Criteria")

支援和意見反應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.