question

LaiKanLeon-4557 avatar image
0 Votes"
LaiKanLeon-4557 asked ReemaRoshanA-5162 answered

EXCEL VBA: Is it possible to use the FILTER function to filter more than one string?

I am posting my question again as it seems it has not been posted.
In case it has already been posted (but I don't see it), please accept my apologies.


Hello,

I sometimes use the VBA Filter function to filter a 1-dimensional array:
Filter(sourcearray, match, [ include, [ compare ]])

But I am wondering:
It it possible to filter an array on 2 strings (e.g. "cats" and "dogs") instead of on only 1 string "cats"?



Dim var As Variant
var = Array("cats", "dogs")
vArray2 = Filter(vArray1, var, True, vbTextCompare)

I tried the above, but it gives an error: "Type Mismatch".

Is there any workaround?

I would like Filter (or any other function) to return all rows containing either "cats" or "dogs" for displaying in a combo box.

Thanks for any help.
Leon



office-vba-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ReemaRoshanA-5162 avatar image
0 Votes"
ReemaRoshanA-5162 answered

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Comments and answers for "EXCEL VBA: Is it possible to use the FILTER function to filter more than one string?"</title>
<link>https://docs.microsoft.com/answers/questions/504909/excel-vba-is-it-possible-to-use-the-filter-functio-1.html</link>;
<description>The latest comments and answers for the question "EXCEL VBA: Is it possible to use the FILTER function to filter more than one string?"</description>
</channel>
</rss>

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.