VBA Filter Function: The Filter function in VBA returns a subset for the given string array, based on specified criteria.

Syntax

Parameter

SourceArray (required) – This parameter the array of Strings that you want to filter.

Match (required) – This parameter the string that you want to search for within each element of the supplied SourceArray.

Include (optional) – This parameter represents the Boolean argument that specifies whether the returns array should consist of elements that include or do not include the supplied Match String.  By default, this parameter is set to True.

It can take the following values:

True (default)- It returns values that include the Match String

False – It returns values that do not include the Match String

Compare (optional) – This parameter represents the type of String to make the comparison. By default, this parameter is set to vbBinaryCompare.

It can take the following values:

vbBinaryCompare (default value)– It performs a binary comparison

vbTextCompare – It performs a text comparison

vbDatabaseCompare – It performs a database comparison

Return

This function returns a subset for the given string array, based on specified criteria.

Example 1

Output

Array Filtered Array
Mumbai Mumbai
Delhi Mumbai
Bangalore
Faridabad
Gurugram
Mumbai
VBA Filter Function

Example 2

Output

Name Sales Amount
Mumbai Delhi
Delhi Bangalore
Bangalore Faridabad
Faridabad Gurugram
Gurugram
Mumbai
VBA Filter Function

Pin It on Pinterest

Share This