Private Sub Worksheet_Activate()
Worksheet_Change [A1] 'lance la macro
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim dat As Range, resu(), n&, i&
Set dat = [D2]
ReDim resu(1 To 5, 1 To 2)
With Sheets("STOCKAGE").[A1].CurrentRegion.Resize(, 6)
.Sort .Columns(1), xlAscending, .Columns(6), , xlDescending, Header:=xlYes 'tri sur les colonnes A et F
n = Application.CountIf(.Columns(1), dat)
If n Then
i = Application.Match(dat.Value2, .Columns(1), 0)
With .Rows(i).Resize(n)
For i = 1 To IIf(n > 5, 5, n)
resu(i, 1) = .Cells(i, 2)
resu(i, 2) = .Cells(i, 6)
Next
End With
End If
End With
'---restitution---
Application.EnableEvents = False 'désactive les évènements
[B11:C15] = resu
Application.EnableEvents = True 'réactive les évènements
End Sub