Name
Filter Function
Syntax
Filter(SourceArray,FilterString[,Switch[,Compare]])
-
SourceArray Use: Required
Data Subtype: String or numeric
An array containing values to be filtered.
-
FilterString Use: Required
Data Subtype: String or numeric
The string of characters to find in the source array.
-
Switch Use: Optional
Data Subtype: Boolean
A Boolean (
TrueorFalse) value. IfTrue, the default value,Filterincludes all matching values inresult; ifFalse,Filterexcludes all matching values (or, to put it another way, includes all nonmatching values).-
Compare Use: Optional
Data Subtype: 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,Filtermatches both character and case. In contrast,vbTextCompareis case-insensitive, matching only character regardless of case.
Programming Tips & Gotchas
SourceArrayelements that areEmptyor that contain zero-length strings (“”) are ignored by theFilter ...
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