Sub FormatageConditionnel()
Dim i&, PA As Range, PB As Range, PC As Range
With ActiveSheet
For i = 1 To .Cells.SpecialCells(xlCellTypeLastCell).Row
If .Cells(i, "B") = "A" Then
Set PA = Union(IIf(PA Is Nothing, .Cells(i, "H"), PA), .Cells(i, "H"))
ElseIf .Cells(i, "B") = "B" Then
Set PB = Union(IIf(PB Is Nothing, .Cells(i, "H"), PB), .Cells(i, "H"))
ElseIf .Cells(i, "B") = "C" Then
Set PC = Union(IIf(PC Is Nothing, .Cells(i, "H"), PC), .Cells(i, "H"))
End If
Next
.Columns("H").FormatConditions.Delete
End With
If Not PA Is Nothing Then
PA.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, Formula1:="=2", Formula2:="5"
PA.FormatConditions(1).Interior.Color = RGB(0, 128, 0)
PA.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, Formula1:="=6", Formula2:="8"
PA.FormatConditions(2).Interior.Color = RGB(255, 255, 0)
PA.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, Formula1:="=9", Formula2:="10"
PA.FormatConditions(3).Interior.Color = RGB(255, 0, 0)
End If
If Not PB Is Nothing Then
PB.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, Formula1:="=3", Formula2:="7"
PB.FormatConditions(1).Interior.Color = RGB(0, 128, 0)
PB.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, Formula1:="=8", Formula2:="11"
PB.FormatConditions(2).Interior.Color = RGB(255, 255, 0)
PB.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, Formula1:="=12", Formula2:="15"
PB.FormatConditions(3).Interior.Color = RGB(255, 0, 0)
End If
If Not PC Is Nothing Then
PC.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, Formula1:="=4", Formula2:="9"
PC.FormatConditions(1).Interior.Color = RGB(0, 128, 0)
PC.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, Formula1:="=10", Formula2:="15"
PC.FormatConditions(2).Interior.Color = RGB(255, 255, 0)
PC.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, Formula1:="=16", Formula2:="20"
PC.FormatConditions(3).Interior.Color = RGB(255, 0, 0)
End If