conditional formatting

ktran

XLDnaute Junior
hello a tous,

je souhaite comparer si la date dans la colonne de G6 a G9000 est egal a D2, si oui, alors colorier la ou les cellules en rouge.
le probleme est que lorsqu'il y a une ou des cellules avec le critere mentionne, rien et en plus, VBA me colorie une autre cellule dans une autre colonne ?

une idee ?

voici le code :

Sub alert_MD()
With Range("G6:G9000")
.Select
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="$D$2"
.FormatConditions(1).Interior.PatternColorIndex = xlAutomatic
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions(1).Interior.TintAndShade = 0
End With
End Sub

merci d avance
 

Pièces jointes

  • untitled.jpg
    untitled.jpg
    53.5 KB · Affichages: 73
  • untitled.jpg
    untitled.jpg
    53.5 KB · Affichages: 77
  • untitled.jpg
    untitled.jpg
    53.5 KB · Affichages: 76

ktran

XLDnaute Junior
Re : conditional formatting

avec ce code, la macro fonctionne quand range ("G6:G23") mais quand je retouche la range a ("G6:G100"), ce la sort :

run-time error "1004"
application-defined or object-defined error + souligne en jaune
.Color = -16383844

une idee du pourquoi ?

Sub alert_MD()
Range("G6:G100").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=$D$2"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
MsgBox " Alert, Expiry of Options.", vbOKOnly
End Sub