Sub MFC_ToutesMatrices()
Dim ws As Worksheet
Set ws = ActiveSheet
Dim Plages As Variant
Dim i As Long
Dim formule As String
Dim fcIndex As Long
' Liste des matrices et première colonne à tester
Plages = Array( _
Array("$A$3:$C$33", "A"), _
Array("$E$3:$G$33", "E"), _
Array("$I$3:$K$33", "I"), _
Array("$M$3:$O$33", "M"), _
Array("$Q$3:$S$33", "Q"), _
Array("$U$3:$X$33", "U"), _
Array("$Y$3:$AA$33", "Y"), _
Array("$AC$3:$AD$33", "AC"), _
Array("$AG$3:$AI$33", "AG"), _
Array("$AK$3:$AM$33", "AK"), _
Array("$AO$3:$AQ$33", "AO"), _
Array("$AS$3:$AU$33", "AS") _
)
' Supprime toutes les MFC existantes
ws.Cells.FormatConditions.Delete
' Boucle sur toutes les matrices
For i = LBound(Plages) To UBound(Plages)
' Construire la formule
formule = "=OU($" & Plages(i)(1) & "3=""SA"";$" & Plages(i)(1) & "3=""DI"")"
' Sélectionner la plage
'ws.Range(Plages(i)(0)).Select
' Ajouter la MFC
ws.Range(Plages(i)(0)).FormatConditions.Add _
Type:=xlExpression, _
Formula1:=formule
'Pour Info (formule) --->>> Formula1:="=OU($A3=""SA"";$A3=""DI"")"
fcIndex = ws.Range(Plages(i)(0)).FormatConditions.Count
' Mettre en première priorité
ws.Range(Plages(i)(0)).FormatConditions(fcIndex).SetFirstPriority
' Police : gras
With ws.Range(Plages(i)(0)).FormatConditions(fcIndex).Font
.Bold = True
End With
' Remplissage vert très clair
With ws.Range(Plages(i)(0)).FormatConditions(fcIndex).Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(198, 239, 206)
End With
' StopIfTrue = False
ws.Range(Plages(i)(0)).FormatConditions(fcIndex).StopIfTrue = False
Next i
' Replacer le curseur sur A1
ws.Range("A1").Select
MsgBox "MFC appliquée sur toutes les matrices !", vbInformation
End Sub