vba: filter column by array of criteria, all elements must be present

时间:2016-10-20 20:13:17

标签: excel vba

I've got a List (Worksheet) and every entry (row) has itself categorized in a cell (in a dedicated row) by comma separated integers.

Reading from a cell I am filtering the list accordingly in a "OR" connection:

e.g.

MyCriteria = Split(ActiveSheet.Range("$A$1").value, ",")

Dim i as Integer
For i=0 To UBound(MyCriteria)
  MyCriteria(i) = "*" & MyCriteria(i) & "*"
Next i

ActiveSheet.Range("$A$5:$E$200").AutoFilter Field:=5, Criteria1:=MyCriteria, Operator:=xlFilterValues

So if I'll enter 1,5,3 into cell A1, the column 5 (E) will be filtered and only rows are shown, in which at least one of the numbers 1, 5 or 3 are present. (this works)

Question:

How do I filter the same thing in a "AND" connection? Meaning all criteria-values must be present for the row to be shown (1,3 and 5 - in whatever order MUST be present).

0 个答案:

没有答案