Sub Resultat()
Dim d As Object, tablo, n&, i, x$, p%
Set d = CreateObject("Scripting.Dictionary")
d.CompareMode = vbTextCompare 'la casse est ignorée
tablo = [A1].CurrentRegion.Resize(, 2) 'matrice, plus rapide, à adapter
tablo(1, 1) = "1ère image"
tablo(1, 2) = "Dernière image"
n = 1
For i = 2 To UBound(tablo)
x = tablo(i, 1)
p = InStrRev(x, "_")
x = Left(x, p)
If p Then
If Not d.exists(x) Then
n = n + 1
d(x) = n 'mémorise la ligne
tablo(n, 1) = tablo(i, 1) '1ère image
End If
tablo(d(x), 2) = tablo(i, 1) 'dernière image
End If
Next
'---restitution---
With Sheets("Résultat")
If .FilterMode Then .ShowAllData 'si la feuille est filtrée
With .[A1] '1ère cellule de restitution, à adapter
.Resize(n, 2) = tablo
.Offset(n).Resize(Rows.Count - n - .Row + 1).ClearContents 'RAZ en dessous
End With
.Columns.AutoFit 'ajustement largeurs
With .UsedRange: End With 'actualise la barre de défilement verticale
.Activate 'facultatif
End With
End Sub