【发布时间】:2019-07-01 20:18:04
【问题描述】:
我在 Excel 2003 工作表中有这个 VBA 函数:
Function ContarColor(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
ContarColor = ContarColor + 1
End If
Next datax
End Function
我使用该函数计算一个范围内的颜色。
例如我使用:
=ContarColor(D4:AG5;Y31)
其中 D4:AG5 是行的范围,Y31 是引用的行颜色。
如果我添加或删除颜色,并且在公式中不按 Enter,它不会刷新。
如何在编辑范围时自动刷新?
【问题讨论】:
-
使用
Sub Worksheet_Change和Range(YourRange).Calculate -
@AntiDrondert,
Worksheet_Change事件处理程序不会被单元格颜色更改触发
标签: excel vba excel-formula