Bonjour à tous,
Et une nouvelle proposition.
Bonnes fêtes de fin d'année.
Cdlt.
Option Explicit
Private Sub cmdFilter_Click()
Dim ws As Worksheet
Dim lo As ListObject
Dim FieldNum As Long, lRow As Long
Dim rng As Range, rng2 As Range
Application.ScreenUpdating = False
Set lo = Me.ListObjects(1)
Set ws = ActiveWorkbook.Worksheets("Feuil2")
FieldNum = 2: lRow = 2
With ws
If Not .ListObjects(1).DataBodyRange Is Nothing Then .ListObjects(1).DataBodyRange.Delete
End With
If Not lo.ShowAutoFilter Then
lo.ShowAutoFilter = True
Else
If lo.AutoFilter.FilterMode Then lo.AutoFilter.ShowAllData
End If
lo.Range.AutoFilter field:=FieldNum, Criteria1:="=x"
With lo.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
MsgBox "Il n'y a aucune donnée filtrée.", vbOKOnly + vbInformation, "Filtre"
GoTo exit_Handler
Else
Set rng = lo.AutoFilter.Range
rng.Offset(1, 0).Resize(rng.Rows.Count - 1) _
.SpecialCells(xlCellTypeVisible).Copy
ws.Cells(lRow, 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End If
ws.Activate
exit_Handler:
lo.Range.AutoFilter field:=FieldNum
Set rng = Nothing: Set rng2 = Nothing
Set lo = Nothing
Set ws = Nothing
End Sub