1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| Option Explicit
Option Base 1
Sub TblFiltres_Appl(LstObj As ListObject, TableauFiltres As Variant)
Dim i As Long
On Error Resume Next
i = UBound(TableauFiltres, 1)
If Err.Number <> 0 Then Exit Sub
On Error GoTo 0
For i = 1 To UBound(TableauFiltres, 2)
ActiveSheet.ListObjects(1).Range.AutoFilter Field:=TableauFiltres(1, i)
Dim Crit1 As Boolean
Dim Crit2 As Boolean
If IsArray(TableauFiltres(2, i)) Then
Crit1 = True
Else
If TableauFiltres(2, i) <> "" Then Crit1 = True
End If
If IsArray(TableauFiltres(4, i)) Then
Crit2 = True
Else
If TableauFiltres(4, i) <> "" Then Crit2 = True
End If
If Crit1 = True And Crit2 = False Then
If TableauFiltres(3, i) = 0 Then
LstObj.Range.AutoFilter Field:=TableauFiltres(1, i), Criteria1:=TableauFiltres(2, i)
Else
LstObj.Range.AutoFilter Field:=TableauFiltres(1, i), Criteria1:=TableauFiltres(2, i), Operator:=TableauFiltres(3, i)
End If
End If
If Crit1 = True And Crit2 = True Then
ActiveWindow.AutoFilterDateGrouping = False
LstObj.Range.AutoFilter Field:=TableauFiltres(1, i), Criteria1:=TableauFiltres(2, i), Operator:=TableauFiltres(3, i), Criteria2:=TableauFiltres(4, i)
End If
If Crit1 = False And Crit2 = True Then
If TableauFiltres(3, i) = 0 Then
LstObj.Range.AutoFilter Field:=TableauFiltres(1, i), Criteria1:=TableauFiltres(4, i)
Else
ActiveWindow.AutoFilterDateGrouping = False
LstObj.Range.AutoFilter Field:=TableauFiltres(1, i), Criteria1:=TableauFiltres(4, i), Operator:=TableauFiltres(3, i)
End If
End If
Crit1 = False
Crit2 = False
Next i
ActiveWindow.AutoFilterDateGrouping = True
End Sub |