Sub Classement()
Dim derlig&, d As Object, n&, x$, tablo, lig&
derlig = Cells.SpecialCells(xlCellTypeLastCell).Row
Application.ScreenUpdating = False
Range("A3:C" & derlig).Sort [A3], xlAscending, Header:=xlNo 'tri
Range("D3:F" & derlig).Sort [D3], xlAscending, Header:=xlNo 'tri
Doublons Range("A3:C" & derlig), 3
Doublons Range("D3:F" & derlig), 3
'---liste des numéros de lignes---
Set d = CreateObject("Scripting.Dictionary")
For n = 3 To derlig
x = CStr(Cells(n, 1))
If x <> "" Then d(x) = n 'mémorise le numéro de ligne
Next n
'---remises en place dans le tableau D E F---
ReDim tablo(1 To derlig - 2, 1 To 3) 'tableau VBA vide (plus rapide)
lig = derlig + 1
For n = 3 To derlig
x = CStr(Cells(n, 4))
If x <> "" Then
If d.exists(x) Then
tablo(d(x) - 2, 1) = Cells(n, 4)
tablo(d(x) - 2, 2) = Cells(n, 5)
tablo(d(x) - 2, 3) = Cells(n, 6)
Else
Cells(n, 4).Resize(, 3).Copy Cells(lig, 4) 'sous le tableau
lig = lig + 1
End If
End If
Next n
[D:D].NumberFormat = "@" 'format Texte
Range("D3:F" & derlig) = tablo 'restitution
Range("F3:F" & derlig).Interior.ColorIndex = xlNone 'RAZ
On Error Resume Next 'si aucune SpecialCell
Range("F3:F" & derlig).SpecialCells(xlCellTypeConstants).Interior.Color = RGB(204, 255, 204) 'vert
'---supprime les lignes entièrement vides---
For n = derlig To 3 Step -1
If Application.CountA(Rows(n)) Then Exit For
Rows(n).Delete
Next n
End Sub
Sub Doublons(plage As Range, col%)
Dim d As Object, i&, x$
Set d = CreateObject("Scripting.Dictionary")
For i = 1 To plage.Rows.Count
x = plage(i, 1)
If x <> "" Then
If d.exists(x) Then
plage(d(x), col) = plage(d(x), col) + plage(i, col)
Else
d(x) = i 'mémorise la ligne
End If
End If
Next
plage.RemoveDuplicates 1, Header:=xlNo 'supprime les lignes en doublon
End Sub