excel条件格式不以格式单元格显示

我有一个条件格式是在单元格中用正确的颜色填充背景,但是当我使用格式单元格来查看单元格并单击填充时,它显示没有填充任何想法为什么会这样。

在那里,我可以指望使用VBA设置格式的颜色。

目前使用下面的代码,并且在颜色索引行失败。

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 

下面的代码将通过每个条件格式化的外部颜色,然后将使用指定的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 

正如simoco在评论中指出的那样,你可以通过Range.DisplayFormat来实现

做类似的事情

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

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