Option Explicit
Dim bon As Boolean
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Coul_1 As Long
Dim Coul_2 As Long
Dim Coul_3 As Long
Dim Coul_4 As Long
Dim Coul_5 As Long
Dim ligne As Range
Dim totalM As Double
Dim totalO As Double
Dim totalI As Double
Dim couleur As Long
Dim c As Range
Dim DernièreColonne As Integer
Dim i As Integer
If bon = True Then
bon = False
Exit Sub
Else
If Target.Row = 9 Then
bon = True
Target = UCase(Target(1))
Select Case Target(1)
Case "M"
Coul_1 = 37 'titre
Coul_2 = 5 ' G
Coul_3 = 33 ' D
Coul_4 = 37 ' colG
Coul_5 = 34 'col D
Case "O"
Coul_1 = 4 'titre
Coul_2 = 50 ' G
Coul_3 = 35 ' D
Coul_4 = 35 ' colG
Coul_5 = 4 'col D
Case "I"
Coul_1 = 3 'titre
Coul_2 = 3 ' G
Coul_3 = 38 ' D
Coul_4 = 38 ' colG
Coul_5 = 3 'col D
Case Else
Coul_1 = -4142 'titre
Coul_2 = -4142 ' G
Coul_3 = -4142 ' D
Coul_4 = -4142 ' colG
Coul_5 = -4142 'col D
End Select
'Titre
Cells(Target.Row - 3, Target.Column).Interior.ColorIndex = Coul_1
Cells(Target.Row + 1, Target.Column).Interior.ColorIndex = Coul_2
Cells(Target.Row + 1, Target.Column + 2).Interior.ColorIndex = Coul_3
Range(Cells(11, Target.Column).Address & ":" & _
Cells(62, Target.Column).Address).Interior.ColorIndex = Coul_4
Range(Cells(11, Target.Column + 2).Address & ":" & _
Cells(62, Target.Column + 2).Address).Interior.ColorIndex = Coul_5
If Coul_5 = -4142 Then MsgBox ("Remise à blanc!")
End If
End If
DernièreColonne = Range("A10").End(xlToRight).Column
For i = 1 To DernièreColonne
If Not Intersect(Target, Range("plage")) Is Nothing Then
Set ligne = Range(Cells(Target.Row, "C"), Cells(Target.Row, DernièreColonne))
For Each c In ligne
couleur = c.Interior.ColorIndex
If couleur = 3 Or couleur = 4 Or couleur = 34 Then
If c = "X" Then
Select Case Cells(9, c.Column - 2)
Case "M": totalM = totalM + c.Offset(0, -1)
Case "I": totalI = totalI + c.Offset(0, -1)
Case "O": totalO = totalO + c.Offset(0, -1)
End Select
End If
End If
Next c
Cells(Target.Row, DernièreColonne + 4) = totalM
Cells(Target.Row, DernièreColonne + 5) = totalI
Cells(Target.Row, DernièreColonne + 6) = totalO
End If
Next i
End Sub