Sub Total_ventes()
Dim ventes, kit, d As Object, i&, code, q&, j&, n&
ventes = [H1].CurrentRegion.Resize(, 3) 'matrice, plus rapide
kit = [A1].CurrentRegion.Resize(, 5)
Set d = CreateObject("Scripting.Dictionary")
For i = 2 To UBound(ventes)
If LCase(ventes(i, 2)) Like "kit*" Then
code = ventes(i, 1)
q = ventes(i, 3)
For j = 2 To UBound(kit)
If kit(j, 1) = code Then d(kit(j, 2)) = d(kit(j, 2)) + q * kit(j, 5)
Next j
Else
d(ventes(i, 1)) = d(ventes(i, 1)) + ventes(i, 3)
End If
Next i
'---restitution---
n = d.Count
With [L4] '1ère cellule de destination, à adapter
If n Then
.Resize(n) = Application.Transpose(d.keys)
.Offset(, 1).Resize(n) = "=IFERROR(VLOOKUP(RC[-1],C2:C3,2,0),VLOOKUP(RC[-1],C8:C9,2,0))"
.Offset(, 2).Resize(n) = Application.Transpose(d.items)
End If
.Offset(n).Resize(Rows.Count - n - .Row + 1, 3).ClearContents 'RAZ en dessous
End With
End Sub