Filter 函数Filter function

返回一个从零开始的数组, 该数组包含基于指定的筛选条件的字符串数组的子集。Returns a zero-based array containing a subset of a string array based on a specified filter criteria.


筛选器(sourcearray, match, [ include, [ compare ]])Filter(sourcearray, match, [ include, [ compare ]])

Filter函数语法包含以下命名参数:The Filter function syntax has these named arguments:

PartPart 说明Description
sourcearraysourcearray 必需。Required. 要搜索的字符串的一维度组。One-dimensional array of strings to be searched.
区分match 必需。Required. 要搜索的字符串。String to search for.
includeinclude 可选。Optional. Boolean 值,指示是否返回包括或排除 match 的子字符串。Boolean value indicating whether to return substrings that include or exclude match. 如果 includeTrue,则 Filter 返回包含 match 作为子字符串的数组的子集。If include is True, Filter returns the subset of the array that contains match as a substring. 如果 includeFalse,则 Filter 返回不包含 match 作为子字符串的数组的子集。If include is False, Filter returns the subset of the array that does not contain match as a substring.
comparecompare 可选。Optional. 指示要使用的字符串比较类型的数值。Numeric value indicating the kind of string comparison to use. 请参阅“设置”部分了解相关值。See Settings section for values.


compare 参数可以包含以下值:The compare argument can have the following values:

常量Constant Value 说明Description
vbUseCompareOptionvbUseCompareOption -1-1 使用 Option Compare 语句的设置来执行比较。Performs a comparison by using the setting of the Option Compare statement.
vbBinaryComparevbBinaryCompare 00 执行二进制比较。Performs a binary comparison.
vbTextComparevbTextCompare 11 执行文本比较。Performs a textual comparison.
vbDatabaseComparevbDatabaseCompare 双面2 仅用于 Microsoft Access。Microsoft Access only. 根据数据库中的信息执行比较。Performs a comparison based on information in your database.

Filter 函数返回的数组只包含足以构成匹配项数的元素。The array returned by the Filter function contains only enough elements to contain the number of matched items.

另请参阅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.