Sub Quantité(Optional Target As Range)
Dim derlig&, tablo() As Boolean, ub%, i%, cel1 As Range, cel2 As Range
Dim t$, Qte1#, Qte2#, v#
derlig = Application.Max([B65536].End(xlUp).Row, [E65536].End(xlUp).Row, [I65536].End(xlUp).Row)
If derlig < 14 Then Exit Sub
If Target Is Nothing Then 'si activation de la feuille
Application.ScreenUpdating = False
Set Target = Range("B14:B" & derlig)
End If
Set Target = Intersect(Target, Range("B14:B" & derlig))
If Target Is Nothing Then Exit Sub
'---validation des feuilles (adapter éventuellement les plages)---
ReDim tablo(1 To Worksheets.Count, 1 To 2)
ub = UBound(tablo)
For i = 1 To ub
If Worksheets(i).[C2].Text <> "" Then
If Not Feuil1.[C6:G35].Find(Worksheets(i).[C2].Text, , xlValues, xlWhole) _
Is Nothing Then tablo(i, 1) = True
If Not Feuil1.[I6:P35].Find(Worksheets(i).[C2].Text) _
Is Nothing Then tablo(i, 2) = True
End If
Next
'---analyse de la feuille---
For Each Target In Target
Set cel1 = Cells(Target.Row, "E"): Set cel2 = Cells(Target.Row, "I")
If IsEmpty(Target) Then 'RAZ
If Not IsEmpty(cel1) Then cel1 = ""
If Not IsEmpty(cel2) Then cel2 = ""
Else
t = Target: Qte1 = 0: Qte2 = 0
For i = 1 To ub
If tablo(i, 1) Or tablo(i, 2) Then
v = Application.SumIf(Worksheets(i).[C7:C39], t, Worksheets(i).[E7:E39])
If tablo(i, 1) Then Qte1 = Qte1 + v
If tablo(i, 2) Then Qte2 = Qte2 + v
End If
Next
cel1 = Qte1: cel2 = Qte2
End If
Next
End Sub