Sub FILTREAVANCE()
Dim critere As Range, ncol%, mem, w As Worksheet, titres As Range, num_facture, d As Object, i&, a(), j&, k%
Application.ScreenUpdating = False
Set critere = Sheets("ANNEXE").[A1:A2]
With Feuil7.[A:G] 'feuille RELANCE 1
ncol = .Columns.Count
mem = .CurrentRegion.Resize(, ncol + 4) 'mémorise A:K
.Rows(2).Resize(.Rows.Count - 1, ncol + 4).Delete xlUp 'RAZ
For Each w In Worksheets
If w.Name Like "ECHEANCIER*" Then
Set titres = .Cells(.Rows.Count, 1).End(xlUp)(2).Resize(, ncol)
.Rows(1).Copy titres
w.Range("A5").CurrentRegion.AdvancedFilter xlFilterCopy, critere, titres
titres.Delete xlUp
End If
Next w
'---restitution des valeurs en colonnes H I J K---
If .CurrentRegion.Rows.Count > 1 Then
num_facture = .Cells(2, 3).Resize(.CurrentRegion.Rows.Count - 1, 2) 'tableau avec au moins 2 éléments
Set d = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(num_facture)
If Not d.exists(num_facture(i, 1)) Then d(num_facture(i, 1)) = i 'repérage de la ligne
Next i
ReDim a(1 To UBound(num_facture), 1 To 4) 'tableau, plus rapide
For i = 2 To UBound(mem)
j = d(mem(i, 3)) 'recherche le n° de facture dans le dictionnaire
If j Then
For k = 1 To 4
a(j, k) = mem(i, ncol + k)
Next k
d.Remove mem(i, 3) 'évite les doublons dans mem
End If
Next i
.Cells(2, ncol + 1).Resize(UBound(a), 4) = a 'restitution
End If
.CurrentRegion.Borders.Weight = xlThin 'bordures
With .Parent.UsedRange: End With 'actualise la barre de défilement verticale
End With
End Sub