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
| Sub FiltreListe()
Dim f1 As Worksheet
Dim f2 As Worksheet
Dim derlig As Long
Application.ScreenUpdating = False
Set f1 = Sheets("base")
Set f2 = Sheets("liste")
Set F3 = Sheets("RESULTAT")
F3.Cells.ClearContents
derlig = f2.Cells(Rows.Count, 1).End(xlUp).Row
lig = f1.Cells(Rows.Count, 1).End(xlUp).Row
If f1.FilterMode = True Then f1.ShowAllData
Set d = CreateObject("scripting.dictionary")
d.CompareMode = vbTextCompare
Dim liste As New Collection
Dim i As Integer
On Error Resume Next
For Each cel In f2.Range("A2:A" & f2.Cells(Rows.Count, 1).End(xlUp).Row)
liste.Add cel.Text, CStr(cel.Text)
Next cel
For Each c In liste: d(c) = "": Next c
Set d2 = CreateObject("scripting.dictionary")
d2.CompareMode = vbTextCompare
For Each c In f1.Range("B2:B" & f1.[B65000].End(xlUp).Row)
If Not d.exists(c.Value) Then d2(c.Value) = ""
Next c
f1.Range(f1.Cells(1, 1), f1.Cells(lig, 2)).AutoFilter Field:=2, Criteria1:=d2.keys, Operator:=xlFilterValues
f1.Range("A1:B" & lig).SpecialCells(xlCellTypeVisible).Copy Destination:=F3.Range("A1")
f1.ShowAllData
Application.ScreenUpdating = True
End Sub |
Partager