【发布时间】:2020-02-07 13:16:45
【问题描述】:
我正在使用我在网上找到的自定义函数。它完成了我需要它做的事情 - 计算一系列单元格中特定颜色的单元格。
如何编辑它以仅计算可见单元格? 我曾尝试使用它,但它没有任何作用。
For Each rCell In CountRange.SpecialCells(xlCellTypeVisible)
完整的功能是这样的:
Function GetColorCount(CountRange As Range, CountColor As Range, Optional VolatileParameter As Variant)
Dim CountColorValue As Integer
Dim TotalCount As Integer
CountColorValue = CountColor.Interior.ColorIndex
Set rCell = CountRange
For Each rCell In CountRange
If rCell.Interior.ColorIndex = CountColorValue Then
TotalCount = TotalCount + 1
End If
Next rCell
GetColorCount = TotalCount
End Function
要在工作表中使用它,然后输入:
=GetColorCount(A1:G20,H1, NOW())
地点:
- A1:G20 是我要统计所有黄色单元格的范围
- H1 是显示计数的单元格,颜色为黄色
- NOW() 让它在每次在范围内进行更改时运行 (??)
有什么建议吗?
【问题讨论】:
-
我相信
SpecialCells不会在UDF中工作