Dear all,
I have an issue with the code below.
The main idea behind this code is to calculate the number of cells which have the same background colour as the particular cell.
the code is working, but when you change the sheet you have to manually refresh it to have proper values.
Even if you save an excel file and get to a different sheet you get bad values. It will be very helpful if someone can tell me how to refresh this code when the excel sheet is changed or how to change the code so changes in one sheet didn't affect values on the other sheets.
Many thanks for your help.
I have an issue with the code below.
VBA Code:
Function CountColor(CellsRange As Range, ReferenceCell As Range) As Integer
Dim indRefColor As Long
Dim Format As Range
Dim CountColor2 As Integer
Application.Volatile
CountColor = 0
indRefColor = Evaluate("cfcolour(" & ReferenceCell.Address & ")")
For Each cell In CellsRange
If Evaluate("CFColour(" & cell.Address & ")") = indRefColor Then
CountColor = CountColor + 1
End If
Next
End Function
Function CFColour(Cl As Range) As Double
CFColour = Cl.DisplayFormat.Interior.Color
End Function
The main idea behind this code is to calculate the number of cells which have the same background colour as the particular cell.
the code is working, but when you change the sheet you have to manually refresh it to have proper values.
Even if you save an excel file and get to a different sheet you get bad values. It will be very helpful if someone can tell me how to refresh this code when the excel sheet is changed or how to change the code so changes in one sheet didn't affect values on the other sheets.
Many thanks for your help.