Bonjour
Problème classique en algorithmique ! Donc cela donnerait en algorithmique pure et basique :
Sub Tri()
Dim tabNoms()
Dim tabTri()
Dim ligFin
Dim cptLig, nbrTri
Dim ligNom
ligFin = Cells(Rows.Count, 1).End(xlUp).Row
tabNoms = Range(Cells(1, 1), Cells(ligFin, 3))
For cptLig = 1 To UBound(tabNoms, 1)
ligNom = TrouveNom(tabTri, tabNoms(cptLig, 1))
If ligNom > 0 Then
tabTri(3, ligNom) = tabTri(3, ligNom) + tabNoms(cptLig, 3)
Else
tabTri = InsereNom(tabTri, tabNoms, cptLig)
End If
Next
tabTri = TriPoints(tabTri)
Cells(2, 5).Resize(UBound(tabTri, 2), UBound(tabTri, 1)) = WorksheetFunction.Transpose(tabTri)
End Sub
Function TriPoints(tabBrut)
Dim iIndice, jIndice
Dim zonSwap
Dim cptCol
For iIndice = 1 To UBound(tabBrut, 2) - 1
For jIndice = iIndice To UBound(tabBrut, 2)
If tabBrut(3, iIndice) < tabBrut(3, jIndice) Then
For cptCol = 1 To 3
zonSwap = tabBrut(cptCol, iIndice)
tabBrut(cptCol, iIndice) = tabBrut(cptCol, jIndice)
tabBrut(cptCol, jIndice) = zonSwap
Next
End If
Next
Next
TriPoints = tabBrut
End Function
Function InsereNom(tabTrier, tabNoms, ligAct)
Dim cptCol
On Error GoTo errInsereNom
ReDim Preserve tabTrier(1 To UBound(tabTrier, 1), 1 To UBound(tabTrier, 2) + 1)
On Error GoTo 0
For cptCol = 1 To UBound(tabNoms, 2)
tabTrier(cptCol, UBound(tabTrier, 2)) = tabNoms(ligAct, cptCol)
Next
InsereNom = tabTrier
Exit Function
errInsereNom:
ReDim tabTrier(1 To 3, 1 To 1)
Resume Next
End Function
Function TrouveNom(tabTrier, nomCherche)
Dim trvNom As Boolean
Dim cptLig
Dim nbrLig
trvNom = False
cptLig = 1
On Error GoTo errTrouveNom
nbrLig = UBound(tabTrier, 2)
On Error GoTo 0
While Not (cptLig > UBound(tabTrier, 2)) And Not trvNom
If (tabTrier(1, cptLig) = nomCherche) Then
trvNom = True
Else
cptLig = cptLig + 1
End If
Wend
TrouveNom = IIf(trvNom, cptLig, 0)
Exit Function
errTrouveNom:
TrouveNom = 0
On Error GoTo 0
End Function
Mais je viens de voir que tu travailles sur GoogleSheet, je sais pas si VBA fonctionne de manière identique...
PS/ Le code n'est pas commenté, mais je pense qu'il se comprend de lui même... Au besoin je peux le commenter !