我在下面写的函数是采用一个范围,我对其进行了一些条件格式设置(用于字体颜色),以及另一个用于比较颜色的单元格范围。功能是统计大范围内有多少个单元格与一个单元格范围具有相同的字体颜色。
Function CountColor(rng As Range, clr As Range) As Integer
Dim c As Range
Dim a As Integer
a = 0
For Each c In rng
If c.DisplayFormat.Font.Color = clr.Font.Color Then
a = a + 1
End If
Next
CountColor = a
End Function
现在,问题是 - 在函数窗口中,实际结果正确,而在单元格本身中,我得到#VALUE!错误。
以下代码对我有用,但不适用于条件格式:
Option Explicit
Function CountColor(rng As Range, clr As Variant) As Variant
Dim c As Range
Dim a As Integer
a = 0
For Each c In rng
If c.Font.color = clr.Font.color Then
a = a + 1
End If
Next c
CountColor = a
End Function
如果我简单地更改字体颜色而不是条件格式,它就可以工作。但由于某种原因它不会工作,否则。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)