Reputation: 141
I made a function in Excel. But after cell update function value is not changed. How to update function cell value after cell changing
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
Upvotes: 1
Views: 495
Reputation: 36840
First use Application.Volatile
beginning of codes then write Me.Calculate
in Worksheet_SelectionChange
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
Upvotes: 1