Private Sub Worksheet_Change(ByVal Target As Range)
Dim nlig&, tablo#(), dico As Object, c As Range, i&, j%, s#, k&, v, TOTAL#
nlig = Range("A1", UsedRange).Rows.Count
ReDim tablo(1 To 12) 'pour les 12 colonnes C à N (fait gagner du temps)
'---liste des Directions---
Set dico = CreateObject("Scripting.Dictionary")
For Each c In [ZListDirection] 'plage nommée
dico(c.Value) = ""
Next c
Application.ScreenUpdating = False
Application.EnableEvents = False 'désactive les évènements
'---Cellule---
For i = 8 To nlig
If Cells(i, 2) Like "Cellule*" Then
For j = 3 To 14 'colonnes C à N
s = 0
For k = i + 1 To nlig
v = Cells(k, 2)
If dico.exists(v) Or v Like "Service*" Or v Like "Cellule*" Then Exit For
v = Cells(k, j)
If IsNumeric(v) Then s = s + CDbl(v)
If j = 3 Then Cells(k, 15) = Application.Sum(Range(Cells(k, 3), Cells(k, 14))) 'total des cellules incolores
Next k
tablo(j - 2) = s
Next j
Range(Cells(i, 3), Cells(i, 14)) = tablo
Cells(i, 15) = Application.Sum(tablo)
End If
Next i
'---Service---
For i = 7 To nlig
If Cells(i, 2) Like "Service*" Then
For j = 3 To 14
s = 0
For k = i + 1 To nlig
v = Cells(k, 2)
If dico.exists(v) Or v Like "Service*" Then Exit For
If v Like "Cellule*" Then
v = Cells(k, j)
If IsNumeric(v) Then s = s + CDbl(v)
End If
Next k
tablo(j - 2) = s
Next j
Range(Cells(i, 3), Cells(i, 14)) = tablo
Cells(i, 15) = Application.Sum(tablo)
End If
Next i
'---Direction---
For i = 6 To nlig
If dico.exists(Cells(i, 2).Value) Then
For j = 3 To 14
s = 0
For k = i + 1 To nlig
v = Cells(k, 2)
If dico.exists(v) Then Exit For
If v Like "Service*" Then
v = Cells(k, j)
If IsNumeric(v) Then s = s + CDbl(v)
End If
Next k
tablo(j - 2) = s
Next j
Range(Cells(i, 3), Cells(i, 14)) = tablo
Cells(i, 15) = Application.Sum(tablo)
TOTAL = TOTAL + Cells(i, 15)
End If
Next i
[O5] = TOTAL
Application.EnableEvents = True 'réactive les évènements
End Sub