Conditional formatting to change ColorIndex?

J

J@Y

I used conditional format to highlight numbers less than 1. That part works.
The cells containing numbers less than 1 appears to be highlighted, but when
I test its ColorIndex, it still shows -4142, which means its blank. I even
went into FormatCell and the Cell shading section was on None. So what
exactly does Conditional Formatting do to the cell property that changes the
color? Can I get it to change the ColorIndex?
 
J

JE McGimpsey

If the condition is true CF applies the value of the ColorIndex property
of the cell's FormatCondition Object.

CF doesn't (and can't) change the ColorIndex property of the cell's
Interior object.

If you want to know whether CF is applied, test the same condition(s)
set in CF.
 
J

JLGWhiz

To check the color index of a conditional format, you have to modify the code
a mite.

Sub whatclr()
MsgBox "ColorIndex number is " & Worksheets(1).Cells(4, 3) _
..FormatConditions(1).Interior.ColorIndex
End Sub

Notice the index number after FormatConditions. It can be one of three
depending on which order it was in the original CF setup.
 
J

JLGWhiz

I just noticed your question about changing the ColorIndex for CF. Yes, you
can change it manually and by code. Just use the FormatConditions() property
in the code structure when doing it by code in the same order as my previous
sample.
 
J

J@Y

Great, that solves things. What exactly does the 1 represent int he () after
FormatConditions?
 

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