DonAndress
Active Member
- Joined
- Sep 25, 2011
- Messages
- 365
- Office Version
- 365
- 2021
- Platform
- Windows
Hello.
What I'm trying to achieve today is to count cells with a certain color and then make excel refresh the cell with such sum automatically.
Below I have a code for counting cells with color and it works fine:
as a formula I put
where K1 contains desired color.
But how do I force Excel to refresh this sum automatically every time I add/remove color to any cell within specified range?
Is it even possible?
Any code inside of ThisWorkbook or Sheet1 area of the VBA Project window?
What I'm trying to achieve today is to count cells with a certain color and then make excel refresh the cell with such sum automatically.
Below I have a code for counting cells with color and it works fine:
Code:
Function CountColorIf(rSample As Range, rArea As Range) As Long Dim rAreaCell As Range
Dim lMatchColor As Long
Dim lCounter As Long
lMatchColor = rSample.Interior.Color
For Each rAreaCell In rArea
If rAreaCell.Interior.Color = lMatchColor Then
lCounter = lCounter + 1
End If
Next rAreaCell
CountColorIf = lCounter
End Function
Code:
=countcolorif($K$1,$A$5:$BC$35)
But how do I force Excel to refresh this sum automatically every time I add/remove color to any cell within specified range?
Is it even possible?
Any code inside of ThisWorkbook or Sheet1 area of the VBA Project window?