View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
FSt1 FSt1 is offline
external usenet poster
 
Posts: 3,942
Default Conditional Formatting using code

hi
set up a true/false condition in the CF cell base on the target cell.
such as if other cell = 0 then true else false
or
=if(b1=0,1,0)

Sub AddCF()
Dim r As Range
Set r = Range("C1") '<--change to suit

r.FormatConditions.Delete
r.FormatConditions.Add _
Type:=xlExpression, Formula1:= _
"=IF(B1=0,1,0)" '<--change to suit
With r.FormatConditions(1).Font
.Bold = True
.Italic = False
.ColorIndex = 3
End With
End Sub

regards
FSt1

"Ayo" wrote:

I am trying to write a contionalformat in code. I have this code ight now:
Range("E1:E10").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="0"
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.ColorIndex = 3
End With

This is not doing what I need. I want a code that would change the font
color in a range of cells based on if the value of another cell is equal to
zero. How do I go about doing this.