VBAmise en forme conditionnelle selon valeurs
Résolu
eglantine217
Messages postés
64
Statut
Membre
-
eglantine217 Messages postés 64 Statut Membre -
eglantine217 Messages postés 64 Statut Membre -
Bonjour,
J'ai deux types de mise en forme à faire.
La première si dans le colonne F ma valeur =1 alors j'ai bleu clair si c'est égale à 2 j'ai turquoise
Jusque là c'est ok ça se complique après et je ne sais pas comment faire :
si F = 1
8 < colonne U< 19 : cellule de B à E et G à U devient orange
20 < U < 39 : B:E et G:U devient jaune
40 <U < 59 : B:E et G:U devient orange foncé
60 < U < 99 : B:E et G:U devient orange très foncé
valeur colonne U > 100 B:E et G:U devient rouge
merci d'avance
J'ai deux types de mise en forme à faire.
La première si dans le colonne F ma valeur =1 alors j'ai bleu clair si c'est égale à 2 j'ai turquoise
With Range("F:F")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="1"
.FormatConditions(1).Interior.ColorIndex = 28
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="2"
.FormatConditions(2).Interior.ColorIndex = 45
End With
Jusque là c'est ok ça se complique après et je ne sais pas comment faire :
si F = 1
8 < colonne U< 19 : cellule de B à E et G à U devient orange
20 < U < 39 : B:E et G:U devient jaune
40 <U < 59 : B:E et G:U devient orange foncé
60 < U < 99 : B:E et G:U devient orange très foncé
valeur colonne U > 100 B:E et G:U devient rouge
merci d'avance
2 réponses
-
Bonjour,
Essaie ce code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) For i = 1 To 500 If Range("F" & i) = 1 And Range("U" & i) > 8 And Range("U" & i) < 19 Then Range("B" & i, "E" & i).Interior.ColorIndex = 3 'Rouge Range("G" & i, "U" & i).Interior.ColorIndex = 44 'orange ElseIf Range("F" & i) = 1 And Range("U" & i) > 20 And Range("U" & i) < 39 Then Range("B" & i, "E" & i).Interior.ColorIndex = 6 'jaune Range("G" & i, "U" & i).Interior.ColorIndex = 6 ElseIf Range("F" & i) = 1 And Range("U" & i) > 40 And Range("U" & i) < 59 Then Range("B" & i, "E" & i).Interior.ColorIndex = 45 'orange foncé Range("G" & i, "U" & i).Interior.ColorIndex = 45 ElseIf Range("F" & i) = 1 And Range("U" & i) > 60 And Range("U" & i) < 99 Then Range("B" & i, "E" & i).Interior.ColorIndex = 46 'orange très foncé Range("G" & i, "U" & i).Interior.ColorIndex = 46 ElseIf Range("F" & i) = 1 And Range("U" & i) > 100 Then Range("B" & i, "E" & i).Interior.ColorIndex = 3 'rouge Range("G" & i, "U" & i).Interior.ColorIndex = 3 ElseIf Range("F" & i) <> 1 Then Range("B" & i, "E" & i).Interior.ColorIndex = xlNone Range("G" & i, "U" & i).Interior.ColorIndex = xlNone ElseIf Range("U" & i) < 8 Then Range("B" & i, "E" & i).Interior.ColorIndex = xlNone Range("G" & i, "U" & i).Interior.ColorIndex = xlNone End If Next i End Sub
où les conditions du genre <19 et >20 seront à revoir car elles laissent des intervalles non pris en considération.
Cordialement. -
Bonjour,
Ce que tu veux faire n'est pas possible avec une MFC. Faudrait un code VBA.
A+