Name
Filter Function
Syntax
Filter(SourceArray,FilterString[,Switch[,Compare]])
SourceArrayUse: Required
Data Type: String or numeric
An array containing values to be filtered.
FilterStringUse: Required
Data Type: String or numeric
The string of characters to find in the source array.
SwitchUse: Optional
Data Type: Boolean
A Boolean (
TrueorFalse) value. IfTrue, the default value, Filter includes all matching values inresult; ifFalse, Filter excludes all matching values (or, to put it another way, includes all nonmatching values).CompareUse: Optional
Data Type: Long
An optional constant (possible values are 0,
vbBinaryCompare; 1,vbTextCompare) that indicates the type of string comparison to use. The default value is 0,vbBinaryCompare.
Return Value
A String array of the elements filtered from
SourceArray.
Description
Produces an array of matching values from an array of source values that either match or don’t match a given filter string. In other words, individual elements are copied from a source array to a target array if they either match or don’t match a filter string.
Rules at a Glance
The default
Switchvalue isTrue.The default
Comparevalue is 0,vbBinaryCompare.vbBinaryCompareis case-sensitive; that is, Filter matches both character and case. In contrast,vbTextCompareis case-insensitive, matching only character regardless of case.
Programming Tips and Gotchas
SourceArrayelements that areEmptyor that contain zero-length strings (“”) are ignored by the Filter function.The array ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access