Coloriser une cellule en fonction d'une autre cellule
hanadiii
-
hanadiii -
hanadiii -
Bonjour,
J'ai dans la colonne D et E des nombres et je veux coloriser les cellules de la colonne B en vert quand D > 3 ET E >3.
J'ai essayé avec le code suivant mais ça ne marche pas :(
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Cell As Range
Dim Cell2 As Range
For Each Cell In Range("D5:D500")
For Each Cell2 In Range("E5:E500")
If Cell.Value > 3 Then
If Cell2.Value > 3 Then
Cell.Offset(0, -2).Interior.ColorIndex = 43
Else
Cell.Offset(0, -2).Interior.ColorIndex = xlNone
End If
End If
Next Cell2
End Sub
J'ai dans la colonne D et E des nombres et je veux coloriser les cellules de la colonne B en vert quand D > 3 ET E >3.
J'ai essayé avec le code suivant mais ça ne marche pas :(
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Cell As Range
Dim Cell2 As Range
For Each Cell In Range("D5:D500")
For Each Cell2 In Range("E5:E500")
If Cell.Value > 3 Then
If Cell2.Value > 3 Then
Cell.Offset(0, -2).Interior.ColorIndex = 43
Else
Cell.Offset(0, -2).Interior.ColorIndex = xlNone
End If
End If
Next Cell2
End Sub
1 réponse
-
Bonsoir,
Tu peux utiliser une mise en forme conditionnelle avec la formule
=ET($D1>3;$E1>3)
applicable sur $B5:$B500
A+-
sinon, avec VBA
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Cell As Range
For Each Cell In Range("D5:D500")
If Cell.Value > 3 And Cell.Offset(0, 1).Value > 3 Then
Cell.Offset(0, -2).Interior.ColorIndex = 43
Else
Cell.Offset(0, -2).Interior.ColorIndex = xlNone
End If
Next Cell
End Sub
A+ -
-