excel条件格式未显示在格式单元格中

excel条件格式未显示在格式单元格中,excel,vba,Excel,Vba,我有一个条件格式,在单元格中用正确的颜色填充背景,但是当我用格式单元格输入单元格并单击填充时,它显示没有填充,也不知道为什么会这样 我可以用VBA数一数consissional格式设置的颜色 目前正在使用下面的代码,但在颜色索引行失败 Function CountRed(MyRange As Range) CountRed = 0 For Each cell In MyRange ColorIndex = cell.DisplayFormat.Interior.ColorIndex If Co

我有一个条件格式,在单元格中用正确的颜色填充背景,但是当我用格式单元格输入单元格并单击填充时,它显示没有填充,也不知道为什么会这样

我可以用VBA数一数consissional格式设置的颜色

目前正在使用下面的代码,但在颜色索引行失败

Function CountRed(MyRange As Range)
CountRed = 0
For Each cell In MyRange
ColorIndex = cell.DisplayFormat.Interior.ColorIndex

If ColorIndex = 43 Then
CountRed = CountRed + 1
End If


Next cell
test = 0

End Function

正如simoco在评论中指出的,您可以通过
Range.DisplayFormat

做点像

MsgBox Range("A1").DisplayFormat.Interior.ColorIndex

获取单元格当前显示的背景色。

下面的代码将遍历每个条件格式的外部颜色,然后使用指定的RGB颜色为单元格着色

Dim MyRange As Range
Set MyRange = Range("F2:J17")

Dim rng As Range

For Each rng In MyRange

If rng.DisplayFormat.Interior.ColorIndex = 3 Then

    rng.Interior.Color = RGB(255, 0, 0)

End If

If rng.DisplayFormat.Interior.ColorIndex = 44 Then

    rng.Interior.Color = RGB(255, 192, 0)

End If
If rng.DisplayFormat.Interior.ColorIndex = 43 Then

    rng.Interior.Color = RGB(146, 208, 80)

End If



Next rng

因为没有填充,所以Excel 2010有条件格式+