I would like to filter thee columns at the same time based on one variable. I use this filter inside a loop to create pdf files that contain data based on this filter.(I removed the code of creating pdf)
Let's see the following example:
Name1 Name2 Name3
Michael George Annet
George Michael Michael
Michael Jorge Annet
Jorge Annet Michtel
There are 3 columns with names, I would like to filter these three columns based on a variable that holds a name. So for example name = "George" then I would like to see every line that contains the name "George" The output looks then:
Name1 Name2 Name3
Michael George Annet
George Michael Michael
I tried the following:
Set ws1 = Worksheets("Rooster")
For i = 1 To SelectionCount
name = NameArray(i)
If ws1.FilterMode Then ws1.ShowAllData
ws1.Range("AB8:AD157").AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=name, _
Unique:=False
Next i
NameArray(i)
is an array that contains all names that are selected by the user. (NameArray()
is a function that is called)
SelectionCount
counts the number of selected cells by the user.
("AB8:AD157")
is the range of three columns where Excel should search for the variable.
There is no error when running this code, but nothing is filtered. What is wrong? Or is the AdvancedFilter not the right choice to use?