Bonsoir à tous,
Version VBA :
Option Explicit
Sub test()
Dim a, e, i As Long, j As Long
Dim dico As Object, AL As Object
Set dico = CreateObject("Scripting.Dictionary")
Set AL = CreateObject("System.Collections.ArrayList")
a = Sheets("Feuil1").Cells(1).CurrentRegion.Value2
For i = 2 To UBound(a, 1)
If Not dico.exists(a(i, 1)) Then
Set dico(a(i, 1)) = CreateObject("Scripting.Dictionary")
End If
If Not AL.contains(a(i, 2)) Then AL.Add a(i, 2)
dico(a(i, 1))(a(i, 2)) = dico(a(i, 1))(a(i, 2)) + a(i, 3)
Next
ReDim a(1 To dico.Count + 1, 1 To AL.Count + 1): AL.Sort
For j = 0 To AL.Count - 1
a(1, j + 2) = AL(j)
Next
i = 1
For Each e In dico
i = i + 1
a(i, 1) = e
For j = 2 To UBound(a, 2)
a(i, j) = dico(e)(a(1, j))
Next
Next
With Sheets.Add.Cells(1).Resize(UBound(a, 1), UBound(a, 2))
.Rows(1).NumberFormat = "@"
.Value = a: .Cells(1).Value = "DEP"
Union(.Columns(1), .Rows(1)).HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Sort .Cells(1), , , , , , , xlYes
With .Offset(1, 1).Resize(.Rows.Count - 1, .Columns.Count - 1)
.NumberFormat = "0.000%"
End With
End With
Set dico = Nothing: Set AL = Nothing
End Sub
klin89