If I conditionally format say Range A1:A10 in Excel 2007 using the CF menu and select 'NewRule/Format all cells based on their values' and set the minimum type to Number and the value to 0 and the Maximum type to number and the value to say 40: then set the format to fill the cells that meet these conditions with a yellow fill color, I get what I expected. In particular, any cell with a numeric value from 0 through 40 has a yellow fill. Blank (empty) cells in the range do not have a fill, as expected.
Now suppose I use the following code:
I find that any empty cells in the range get a yellow fill, not what I expected, otherwise the result is identical to the menu-driven CF.
If I make the following one-line change to the code, I get the same result as the menu-driven CF, that is, blank cells are not filled.
Where I have changed 0 to an arbitrarily small number greater than 0.
Any thoughts on why there is this apparent difference, and how to prevent blank cells from being filled with color if the 0 is replaced by a negative number?
Now suppose I use the following code:
Rich (BB code):
Sub TestCF()
Dim rng As Range
Set rng = Range("A1:A10")
With rng
For i = .FormatConditions.Count To 1 Step -1
.FormatConditions(i).Delete
Next i
.FormatConditions.Add xlCellValue, xlBetween, 0, 40
.FormatConditions(1).Interior.ColorIndex = 6
End With
End Sub
If I make the following one-line change to the code, I get the same result as the menu-driven CF, that is, blank cells are not filled.
Rich (BB code):
.FormatConditions.Add xlCellValue, xlBetween, 1E-32, 40
Any thoughts on why there is this apparent difference, and how to prevent blank cells from being filled with color if the 0 is replaced by a negative number?