Option Explicit
Option Base 1
Option Compare Text
Dim i As Long, h As Long, LFin As Long
Dim Ws As Worksheet
Dim ColL As String, ColM As String
Dim tabl()
Dim NbMoy As Integer, LStart As Integer
Sub Moyenne()
Set Ws = Sheets("Feuil1")
'Colonne où se trouve les livraisons
ColL = "A"
'Colonne où se trouve les poids totals par BL
ColM = "L"
'Ligne de départ du tableau
LStart = 3
NbMoy = 0
'3 est la ligne de départ du tableau
With Ws
LFin = .Range(ColL & 65536).End(xlUp).Row
tabl = .Range(ColL & LStart & ":" & ColM & LFin).Value
ReDim Preserve tabl(UBound(tabl()), UBound(tabl(), 2) + 1)
For i = LBound(tabl()) To UBound(tabl())
For h = LBound(tabl()) To UBound(tabl())
If tabl(h, LBound(tabl(), 2)) = tabl(i, LBound(tabl(), 2)) Then
tabl(i, UBound(tabl(), 2)) = tabl(i, UBound(tabl(), 2)) + tabl(h, UBound(tabl(), 2) - 1)
NbMoy = NbMoy + 1
End If
Next h
If NbMoy > 0 Then tabl(i, UBound(tabl(), 2)) = tabl(i, UBound(tabl(), 2)) / NbMoy
NbMoy = 0
Next i
.Range(Cells(LStart, .Range(ColL & 1).Column), .Cells(LFin, Range(ColM & 1).Column + 1)).Value = tabl
End With
End Sub