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
| Sub SupprimerEtRemettreFiltre()
'Dim TABFILTRE()
'Application.StatusBar = "Stockage des critères de filtrage..."
Set W = Worksheets("DONNÉES")
With W.AutoFilter
ZONEFILTRE = .Range.Address
With .Filters
ReDim TABFILTRE(1 To .Count, 1 To 3)
For F = 1 To .Count
With .Item(F)
If .On Then
TABFILTRE(F, 1) = .Criteria1
If .Operator Then
TABFILTRE(F, 2) = .Operator
TABFILTRE(F, 3) = .Criteria2
End If
End If
End With
Next
End With
For I = 1 To .Filters.Count
If Not TABFILTRE(I, 1) = "" Then .Range.AutoFilter FIELD:=I
Next
End With
Application.StatusBar = "Critères de filtrage stockés...Filtres enlevés..."
'-------------------------------
'Le code
'-------------------------------
Application.StatusBar = "Rétablissement des filtres..."
For Col = 1 To UBound(TABFILTRE(), 1)
If Not IsEmpty(TABFILTRE(Col, 1)) Then
If TABFILTRE(Col, 2) Then
W.Range(CURRENFILTRANGE).AutoFilter FIELD:=Col, _
Criteria1:=TABFILTRE(Col, 1), Operator:=TABFILTRE(Col, 2), _
Criteria2:=TABFILTRE(Col, 3)
Else
W.Range(ZONEFILTRE).AutoFilter FIELD:=Col, _
Criteria1:=TABFILTRE(Col, 1)
End If
End If
Next
Application.StatusBar = "Critères de filtrage rétablis..."
End Sub |
Partager