Sub MiseEnForme(Sh As Worksheet, Target As Range)
Dim Exclues
Dim LastLig&
Dim LastCol&
Dim R As Range
Dim Rdate As Range
Dim Rp As Range
Dim Rm As Range
Dim Rs As Range
Dim C As Range
Dim cpt&
On Error GoTo Erreur
Exclues = Array("Exposé", "titi", "toto") 'Feuilles exclues du traitement A adapter
For cpt& = LBound(Exclues) To UBound(Exclues)
If Sh.Name = Exclues(cpt&) Then Exit Sub
Next cpt&
LastLig& = Sh.[a65536].End(xlUp).Row
LastCol& = Sh.[iv2].End(xlToLeft).Column
cpt& = 3
Set R = Application.Intersect(Target, Sh.Range(Sh.Cells(3, cpt&), Sh.Cells(LastLig&, LastCol&)))
If R Is Nothing Then Exit Sub
Set R = Nothing
Application.ScreenUpdating = False
Set R = Sh.Range(Sh.Cells(2, cpt&), Sh.Cells(LastLig&, LastCol&))
R.Interior.ColorIndex = xlNone
Set R = Nothing
Set Rdate = Sh.Range(Sh.Cells(2, cpt&), Sh.Cells(2, LastCol&))
Rdate.Interior.ColorIndex = 39
For Each C In Rdate
If IsDate(C) Then
If Weekday(C, vbMonday) > 5 Then
If R Is Nothing Then
Set R = Sh.Range(Sh.Cells(2, cpt&), Sh.Cells(LastLig, cpt&))
Else
Set R = Application.Union(R, Sh.Range(Sh.Cells(2, cpt&), Sh.Cells(LastLig&, cpt&)))
End If
End If
End If
cpt& = cpt& + 1
Next C
R.Interior.ColorIndex = 40
Set R = Nothing
cpt& = 3
Set R = Sh.Range(Sh.Cells(3, cpt&), Sh.Cells(LastLig&, LastCol&))
For Each C In R
Select Case C
Case "P"
If Rp Is Nothing Then
Set Rp = C
Else
Set Rp = Application.Union(Rp, C)
End If
Case "M"
If Rm Is Nothing Then
Set Rm = C
Else
Set Rm = Application.Union(Rm, C)
End If
Case "S"
If Rs Is Nothing Then
Set Rs = C
Else
Set Rs = Application.Union(Rs, C)
End If
End Select
cpt& = cpt& + 1
Next C
If Not Rp Is Nothing Then Rp.Interior.ColorIndex = 37
If Not Rm Is Nothing Then Rm.Interior.ColorIndex = 38
If Not Rs Is Nothing Then Rs.Interior.ColorIndex = 44
Erreur:
Application.ScreenUpdating = True
If Err <> 0 Then MsgBox "Erreur " & Err.Number & vbCrLf & _
Err.Description
End Sub