如何在excel中重复函数
我用Excel做了一个函数。但在单元更新后,函数值不变。单元更改后如何更新功能单元值如何在excel中重复函数,excel,vba,Excel,Vba,我用Excel做了一个函数。但在单元更新后,函数值不变。单元更改后如何更新功能单元值 Public Function SumaByColor(ByVal ColorIndex As Range, ByVal TableRange As Range) As Double Dim cell As Range Dim colorIndexNumber As Integer Dim colorSum As Double colorIndexNumber = ColorIndex.Interior.C
Public Function SumaByColor(ByVal ColorIndex As Range, ByVal TableRange As Range) As Double
Dim cell As Range
Dim colorIndexNumber As Integer
Dim colorSum As Double
colorIndexNumber = ColorIndex.Interior.ColorIndex
For Each cell In TableRange
If cell.Interior.ColorIndex = colorIndexNumber Then
colorSum = colorSum + 1
End If
Next cell
SumaByColor = colorSum
End Function
首先使用
Application.Volatile
代码开头,然后在工作表中写入Me.Calculate
\u selection change
Public Function SumaByColor(ByVal ColorIndex As Range, ByVal TableRange As Range) As Double
Application.Volatile
Dim cell As Range
Dim colorIndexNumber As Integer
Dim colorSum As Double
colorIndexNumber = ColorIndex.Interior.ColorIndex
For Each cell In TableRange
If cell.Interior.ColorIndex = colorIndexNumber Then
colorSum = colorSum + 1
End If
Next cell
SumaByColor = colorSum
End Function
工作表\u选择更改:
AFAIK,更改某些单元格中的颜色不会触发计算。您需要使用
F9
强制重新计算,或者最终您可以截取工作表\u SelectionChange
。例如,我在工作表\u SelectionChangeMe中写了什么。计算
。