Bonjour,
Ton fichier comporte 3 colonnes supplémentaires et le nom de la feuille 'Données' un espace en fin de chaîne.
La colonne PointGEO était en colonne 5 et elle en colonne 8 maintenant.
J'ai modifié la procédure en conséquence.
Cdlt.
Option Explicit
Public Sub Filter_Data()
'Déclaration des variables
Dim lo As ListObject, lo2 As ListObject
Dim Dict As Object
Dim rStart As Range, rng As Range
Dim tbl As Variant, v As Variant
Dim i As Long
Dim lr As ListRow
Application.ScreenUpdating = False
'Initialisation des variables
Set lo = Worksheets("Données").ListObjects(1) 'Tableau1 (voir gestionnaire de noms)
Set lo2 = Worksheets("Résultat").ListObjects(1) 'Tableau2 (voir gestionnaire de noms)
Set Dict = CreateObject("Scripting.Dictionary")
'Efface les données du tableau en conservant les formats et les formules
With lo2
If Not .DataBodyRange Is Nothing Then .DataBodyRange.Delete
'Cellule pour restitution des données
Set rStart = .InsertRowRange
End With
'Tri par nom_ligne de bus (colonne 2) et PointGEO (colonne 8)
With lo
.Sort.SortFields.Add Key:=.ListColumns(2).DataBodyRange, _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=.ListColumns(8).DataBodyRange, _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.Sort.Apply
.Sort.SortFields.Clear
End With
'Création tableau valeurs uniques nom_ligne
'(Utilisation d'un dictionnaire)
tbl = lo.ListColumns(2).DataBodyRange.Value
For i = LBound(tbl) To UBound(tbl)
Dict(tbl(i, 1)) = ""
Next i
'Filtre pour chaque élément du tableau (nom_ligne)
For Each v In Dict.Keys
lo.Range.AutoFilter field:=2, Criteria1:=v
Set rng = lo.AutoFilter.Range
'1ère. ligne visible de la plage filtrée (hors en-tête de colonne))
Set lr = lo.ListRows(rng.Offset(1).SpecialCells(xlCellTypeVisible).Row - 1)
lr.Range.Copy
rStart.PasteSpecial xlPasteValues
Application.CutCopyMode = False
Set rStart = lo2.HeaderRowRange.Cells(1).Offset(lo2.ListRows.Count + 1)
'Dernière ligne visible de la plage filtrée
Set lr = lo.ListRows(rng.SpecialCells(xlCellTypeLastCell).Row - 1)
lr.Range.Copy
rStart.PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Cellule pour prochaine copie
Set rStart = lo2.HeaderRowRange.Cells(1).Offset(lo2.ListRows.Count + 1)
Next v
'On affiche toutes les données
lo.Range.AutoFilter field:=2
'RAZ variables
Set lr = Nothing
Set rStart = Nothing: Set rng = Nothing
Set lo2 = Nothing: Set lo = Nothing
Set Dict = Nothing
End Sub