【发布时间】:2017-07-18 23:10:57
【问题描述】:
我有一个 VBA 可以计算彩色单元格的数量。 VBA 模块分配给一个单元。但是,该函数仅在我单击单元格函数并按 ENTER 时运行。更改单元格值不会自动运行该函数。 选项中也启用了公式的自动更新。
这是我的 VBA:
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function
我使用工作表命令调用此模块:=ColorFunction(J70,$B$3:$BV$66)
有什么帮助吗?? 谢谢
【问题讨论】: