Function CountCcolor(range_data As range, criteria As range) As Long
Dim datax As range
Dim xcolor As Long
xcolor = criteria.Interior.ColorIndex
For Each datax In range_data
If datax.Interior.ColorIndex = xcolor Then
CountCcolor = CountCcolor + 1
End If
Next datax
End Function
1 回答
您可以使用VBA创建UDF(用户定义函数)并将其保存到加载项文件中,以便可以在每个工作簿和其他计算机上使用它 .
Microsoft有一篇知识文章解释如何执行此操作,可以找到HERE . (https://support.microsoft.com/en-gb/kb/2815384)
基本上使用的代码是:
现在在单元格中,您想要计算用于写入函数的颜色:
=CountCcolor(range_data,criteria)
“range_data”指的是您想要计算颜色数量的范围,“criteria”应该是您想要计算的颜色的单元格的单元格引用 .