Dim crit$() 'mémorise la variable
Function Comparer(plage As Range) As Boolean
Dim i%
Comparer = True
For i = 1 To UBound(crit)
If Not LCase(plage(i)) Like crit(i) Then Comparer = False: Exit Function
Next
End Function
Sub Filtrer()
Dim deb As Range, ncol%, critere As Range, fin As Range, i%
Set deb = Feuil1.[F22] '1ère cellule, à adapter
ncol = 21 'à adapter
Set critere = Feuil1.[F22:I22] 'plage à adapter
Set fin = deb.Resize(, ncol).EntireColumn.Find("*", , xlValues, , xlByRows, xlPrevious)
If fin Is Nothing Then Exit Sub 'sécurité
If fin.Row < deb.Row + 1 Then Exit Sub 'tableau vide
ReDim crit(1 To critere.Count) 'tableau, plus rapide
For i = 1 To UBound(crit): crit(i) = "*" & IIf(critere(i) = "", "", LCase(critere(i)) & "*"): Next
Application.ScreenUpdating = False
With deb.Resize(fin.Row - deb.Row + 1, ncol)
.Rows(2).EntireRow.Insert
.Cells(2, 1) = "c1": .Cells(2, 1).AutoFill .Cells(2, 1).Resize(, ncol) 'titres provisoires
.Cells(3, ncol + 1) = "=Comparer(F24:I24)+Comparer(M24:P24)+Comparer(T24:W24)"
.Offset(1).AdvancedFilter xlFilterInPlace, .Cells(2, ncol + 1).Resize(2) 'filtre avancé
.Cells(3, ncol + 1) = ""
.Rows(2).EntireRow.Delete
End With
End Sub
Sub RAZ()
If Feuil1.FilterMode Then Feuil1.ShowAllData
End Sub