VBAmise en forme conditionnelle selon valeurs

Résolu/Fermé
eglantine217 Messages postés 54 Date d'inscription mardi 8 mai 2012 Statut Membre Dernière intervention 3 mars 2013 - 12 juin 2012 à 09:58
eglantine217 Messages postés 54 Date d'inscription mardi 8 mai 2012 Statut Membre Dernière intervention 3 mars 2013 - 13 juin 2012 à 13:37
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

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

g Messages postés 1262 Date d'inscription vendredi 23 avril 2004 Statut Membre Dernière intervention 15 mai 2017 572
13 juin 2012 à 09:00
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.
1
eglantine217 Messages postés 54 Date d'inscription mardi 8 mai 2012 Statut Membre Dernière intervention 3 mars 2013
13 juin 2012 à 13:37
j'ai commencé à travailler dessus ça marche mille merci pour votre aide précieuse bonne continuation !
0
lermite222 Messages postés 8702 Date d'inscription dimanche 8 avril 2007 Statut Contributeur Dernière intervention 22 janvier 2020 1 190
12 juin 2012 à 23:26
Bonjour,
Ce que tu veux faire n'est pas possible avec une MFC. Faudrait un code VBA.
A+
-1