Sub GrandesValeurs()
Dim D() As Variant, R() As Variant
Set d1 = CreateObject("Scripting.Dictionary")
R = Range("A2:E" & [A65000].End(xlUp).Row)
For Each c In Range("A2", [A65000].End(xlUp))
temp = c.Value
If Not d1.exists(temp) Then
d1.Add temp, temp
End If
Next c
D = Application.Transpose(d1.keys)
'ICI ERREUR !!!
ReDim Preserve D(UBound(D), UBound(R, 2) - 1)
temp = 0 'NCS
temp1 = 0 'QS
temp2 = 0 'QT
For i = LBound(D) To UBound(D)
For j = LBound(R) To UBound(R)
If D(i, 1) = R(j, 1) Then
L1 = j: L2 = j
If R(j, 4) > temp1 Then
temp1 = R(j, 4)
L1 = j
End If
If R(j, 5) > temp2 Then
temp2 = R(j, 5)
L2 = j
End If
End If
Next j
If R(L2, 2) > R(L1, 2) Then temp = R(L2, 2) Else temp = R(L1, 2)
D(i - 1, 2) = temp: D(i - 1, 3) = temp1: D(i - 1, 4) = temp2
Next i
MsgBox "Val QS = " & temp1 & ", à la ligne L1=" & L1 & vbCrLf & _
"Val QT = " & temp2 & ", à la ligne L2=" & L2 & vbCrLf & _
"Val NCS = " & temp
Range("G2").Resize(UBound(D), 4) = D
End Sub