Peter Davison
Active Member
- Joined
- Jun 4, 2020
- Messages
- 451
- Office Version
- 365
- Platform
- Windows
Is it possible to count cells by colour in Excel?
I read on a website is wasn't possible unless the code below was added.
Do you feel this is possible?
I am on 365
Thanks for your help
Function CountCellsByColor(data_range As Range, cell_color As Range) As Long
Dim indRefColor As Long
Dim cellCurrent As Range
Dim cntRes As Long
Application.Volatile
cntRes = 0
indRefColor = cell_color.Cells(1, 1).Interior.Color
For Each cellCurrent In data_range
If indRefColor = cellCurrent.Interior.Color
Then
cntRes = cntRes + 1
End If
Next cellCurrent
CountCellsByColor = cntRes
End Function
I read on a website is wasn't possible unless the code below was added.
Do you feel this is possible?
I am on 365
Thanks for your help
Function CountCellsByColor(data_range As Range, cell_color As Range) As Long
Dim indRefColor As Long
Dim cellCurrent As Range
Dim cntRes As Long
Application.Volatile
cntRes = 0
indRefColor = cell_color.Cells(1, 1).Interior.Color
For Each cellCurrent In data_range
If indRefColor = cellCurrent.Interior.Color
Then
cntRes = cntRes + 1
End If
Next cellCurrent
CountCellsByColor = cntRes
End Function