The problem that you are having is that you can't have wildcards ("/*") when you filter on an array.
Getting around that restriction is difficult, but not impossible. The way I've done it before is to do something like this:
1) Copy all of the values in the column you are filtering on (column 2, I think) to a blank sheet.
2) Remove duplicates.
3) Loop through all of the remaining rows and delete any that do not match the criteria.
4) Put the remaining values in an array.
5) Filter the original data on that array.
I don't have access to the code, but it is something like what is below. I didn't test it. I'm not on a computer with Excel right now so you will have to clean it up, fix the errors and also enable Regular Expressions in Visual Basic. Should be in the Tools->References menu. You can also tinker with this code a bit to manipulate it to do it.
Dim i As Integer
Dim c As Integer
Dim lRow As Integer
Dim regEx As New RegExp
Dim rEx As String
Dim arr(1) As String
lRow = Range(shSheet.Rows.Count, ActiveCell.Column).End(xlup).Row 'Get's the last row of the current column selected so make sure to select the column you are trying to filter.
rEx = "^.*(valerie dupond|emanuel babri|raphael gerand).*$" ' The test string for the Regular Expression to match
'Setting up the Regular Expression.
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With
i = 0 'Sets i to be looped through your values.
c = 1 'C will be set to store the values in the array.
'Loops through every row in your table trying to match the pattern above
For i to lRow
If regEx.Test(LCase(ActiveCell.Value)) Then
arr(c) = ActiveCell.Value
c = c + 1
ReDim Preserve arr(c)
End If
ActiveCell.Offset(1,0).Select
Next i
'Sets the filter
Worksheets("Feuil1").Range("A1").AutoFilter field:=2, Criteria1:=arr , ''Operator:=xlFilterValues
Method 2:
Two points:
- You don't need the FOR loop. Criteria1=tab will filter for all the criteria, no loop needed
- You cannot use wildcards if you are using this array method to search for multiple terms. If you want to use wildcards, you have to use different syntax and are limited to just two terms
code 2
Just remove the wildcards. For example if you need to just match "valerie dupond" but not "Mrs. valerie dupond"
Sub FilterMe()
Dim names(3) As String
names(0) = "valerie dupond"
names(1) = "emanuel babri"
names(2) = "raphael gerand"
Worksheets("Feuil1").Range("A1").AutoFilter field:=2, Criteria1:=names, Operator:=xlFilterValues
End Sub
Again you cannot use autofilter to filter more than two terms with wildcards