Results 1 to 5 of 5

Thread: Count cell by colour

  1. #1
    Neophyte Saif00's Avatar
    Join Date
    Apr 2019
    Posts
    2
    Articles
    0
    Excel Version
    2015

    Count cell by colour



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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

  2. #2
    Super Moderator p45cal's Avatar
    Join Date
    Dec 2012
    Posts
    1,551
    Articles
    0
    Excel Version
    365
    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-addi...y-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
    Attached Files Attached Files

  3. #3
    Super Moderator p45cal's Avatar
    Join Date
    Dec 2012
    Posts
    1,551
    Articles
    0
    Excel Version
    365
    Delete as inappropriate:
    1. That worked well, thanks.
    2. That was useless, never try and help me again.

  4. #4
    Administrator Pecoflyer's Avatar
    Join Date
    Oct 2011
    Location
    Brussels Belgium
    Posts
    1,655
    Articles
    0
    Excel Version
    2010 on Xubuntu
    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.
    Thank you Ken for this secure forum.

  5. #5
    Neophyte Saif00's Avatar
    Join Date
    Apr 2019
    Posts
    2
    Articles
    0
    Excel Version
    2015
    Quote Originally Posted by p45cal View Post
    Delete as inappropriate:
    1. That worked well, thanks.
    2. .
    Works great thanks!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •