Count cell by colour

Saif00

New member
Joined
Apr 12, 2019
Messages
2
Reaction score
0
Points
0
Excel Version(s)
2015
I am trying to count the total number of cells that have a particular colour. I have attached the sheet in question and need values under "Total" for the particular colours.

Thanks
 

Attachments

  • Copy of Acoustic Testing Tracker (00000005) (Autosaved).xlsx
    47.4 KB · Views: 18
You have merged cells - ugh. Complicates things.
Attached has formulae in cells O10,O12,O14,O16,O18 (I can't find "Totals" anywhere on the sheet).
It uses a user-defined function CountCellsByColor adapted from that in https://www.ablebits.com/office-addins-blog/2013/12/12/count-sum-by-color-excel/
Code:
Function CountCellsByColor(rData As Range, cellRefColor As Range) As Long
Dim indRefColor As Long
Dim cellCurrent As Range
Dim cntRes As Long, DoneCells As Range, zz As Range
 
Application.Volatile
cntRes = 0
indRefColor = cellRefColor.Cells(1, 1).Interior.Color
For Each cellCurrent In rData
Set zz = Nothing
On Error Resume Next
Set zz = Intersect(cellCurrent, DoneCells)
On Error GoTo 0
  If zz Is Nothing Then
    If indRefColor = cellCurrent.Interior.Color Then
      cntRes = cntRes + 1
    End If
  End If
  If DoneCells Is Nothing Then Set DoneCells = cellCurrent.MergeArea Else Set DoneCells = Union(DoneCells, cellCurrent.MergeArea)
Next cellCurrent
CountCellsByColor = cntRes
End Function
 

Attachments

  • ExcelGuru9933Acoustic Testing Tracker (00000005).xlsm
    51.6 KB · Views: 11
Delete as inappropriate:
1. That worked well, thanks.
2. That was useless, never try and help me again.
 
Hi and welcome
Please,do not crosspost your question on multiple forums without including links here to the other threads on other forums.

Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).
If you have fewer than 10 posts here, you will not be able to post a link, but you must still tell us where else you have asked the question

Do not post any further responses in this thread until a link has been provided to these cross posts.
 
Back
Top