I am trying to write a macro to count cells based on color.
Can you help me?
Hi,
This tutorial covers counting coloured cells: https://www.myonlinetraininghub.com/count-sum-and-average-colored-cells
Mynda
So, do I have to sum the columns before I can actually count the cells based on the tutorial illustration. I'm missing a step.
No, but you've commented out the code in your workbook and merged two lines together. It should look like this:
Function CountCcolor(range_data As Range, criteria As Range) As Long
Application.Volatile True
Dim datax As Range
Dim xcolor As Longxcolor = criteria.Interior.ColorIndex
For Each datax In range_data
If datax.Interior.ColorIndex = xcolor Then
CountCcolor = CountCcolor + 1
End If
Next datax
End Function
with no apostrophes at the start of each line. Note that you need the function to be volatile to have any chance of it calculating correctly, but note also that changing a cell colour does not trigger a recalculation, so this approach is, in my opinion, fundamentally flawed anyway.