conditional formatting

S

scrabtree

I have wrote a VBA code to add conditional formatting to a
cell. Here is the code:

With Sheets("T.S.").Range("AD10")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression,
Formula1:= _
"=IF(AD10=895,0,IF(AD10=0,0,1))"
.FormatConditions(1).Font.ColorIndex = xlAutomatic
.FormatConditions(1).Interior.ColorIndex = 3

However...it isn't adding the formatting???
 
F

Frank Kabel

Hi
the following works for me:
Sub foo()
With Sheets("T.S.").Range("AD10")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, _
Formula1:= _
"=(AD10<>895)*(AD10<>0)"
.FormatConditions(1).Font.ColorIndex = xlAutomatic
.FormatConditions(1).Interior.ColorIndex = 3
End With
End Sub
 
S

scrabtree23

It isn't that my formula doesn't work, it is that the
conditional formatting just doesn't save???
 
S

scrabtree23

When I click on the sheet, then click on the cell, then
check the conditional formatting, it isn't there.
 
F

Frank Kabel

Hi
this works for me (so I can see this condition within the dialog). Have
you tried this code as 'stand-alone'
 
D

David McRitchie

Did you select cell AD10 of sheet 'T.S.' before you looked at conditional formatting
because that is the only cell that the C.F. is applied to in the macro...
---
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top