+ Reply to Thread
Results 1 to 7 of 7

Looking to count status based on Cell color

  1. #1
    Registered User
    Join Date
    04-07-2020
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    45

    Looking to count status based on Cell color

    Hi ,

    I have a big set in which i need to count days based on certain colors. I have attached a sample set, please if you can assist with below. I have written the criteria below as well as in the sheet. Thanks.

    1) Looking For Approved, Reject Or Partial Status In Column H. Green Color Denotes Approved, Red Is Rejected, And If Both Are Present In One Row Is Partial
    2 ) Ron Has Applied 2 Bids, Primary And Secondary
    Based On The Color Primary One Should Come As Rejected In Cell H5
    And Based On Both Green And Red Color Secondary (Cell H6) Should Come As Partial
    3) Number of accepted or rejected bids should be counted in Column I and J respectively based on the color.
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: Looking to count status based on Cell color

    Excel cannot count based on cell colour.

    You present us with one problem after another - do you ever give yourself time to have a go at it yourself before asking us?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    04-07-2020
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    45

    Re: Looking to count status based on Cell color

    Thank you, currently I am working on different sets today however i tried first and then googled the same problem first. With no specific solution to the problem, I considered posting in the group. I got stuck in counting the colors.

    Thank you for the help.

  4. #4
    Registered User
    Join Date
    04-07-2020
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    45

    Re: Looking to count status based on Cell color

    finally got an alternate solution with VBA. no direct formula to calculate that. Thanks.

  5. #5
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Looking to count status based on Cell color

    Please post your solution, for the benefit of all forumusers.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  6. #6
    Registered User
    Join Date
    04-07-2020
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    45

    Re: Looking to count status based on Cell color

    Sure,

    1. Save excel as macro enabled workbook
    2. Press Alt + F11
    3. Right click on the sheet name on the upper left of editor page.
    4. Go to Insert >> Module and paste below code :
    5. Save the workbook. Use CountCellsByColor(range, color code cell)
    For eg: If A1 to A11 is the range in which the colors are, and color is in B1 , formula will be
    CountCellsByColor(A1:A11,B1)

    The code for point 4 is :

    Function GetCellColor(xlRange As Range)
    Dim indRow, indColumn As Long
    Dim arResults()

    Application.Volatile

    If xlRange Is Nothing Then
    Set xlRange = Application.ThisCell
    End If

    If xlRange.Count > 1 Then
    ReDim arResults(1 To xlRange.Rows.Count, 1 To xlRange.Columns.Count)
    For indRow = 1 To xlRange.Rows.Count
    For indColumn = 1 To xlRange.Columns.Count
    arResults(indRow, indColumn) = xlRange(indRow, indColumn).Interior.Color
    Next
    Next
    GetCellColor = arResults
    Else
    GetCellColor = xlRange.Interior.Color
    End If
    End Function

    Function GetCellFontColor(xlRange As Range)
    Dim indRow, indColumn As Long
    Dim arResults()

    Application.Volatile

    If xlRange Is Nothing Then
    Set xlRange = Application.ThisCell
    End If

    If xlRange.Count > 1 Then
    ReDim arResults(1 To xlRange.Rows.Count, 1 To xlRange.Columns.Count)
    For indRow = 1 To xlRange.Rows.Count
    For indColumn = 1 To xlRange.Columns.Count
    arResults(indRow, indColumn) = xlRange(indRow, indColumn).Font.Color
    Next
    Next
    GetCellFontColor = arResults
    Else
    GetCellFontColor = xlRange.Font.Color
    End If

    End Function

    Function CountCellsByColor(rData As Range, cellRefColor As Range) As Long
    Dim indRefColor As Long
    Dim cellCurrent As Range
    Dim cntRes As Long

    Application.Volatile
    cntRes = 0
    indRefColor = cellRefColor.Cells(1, 1).Interior.Color
    For Each cellCurrent In rData
    If indRefColor = cellCurrent.Interior.Color Then
    cntRes = cntRes + 1
    End If
    Next cellCurrent

    CountCellsByColor = cntRes
    End Function

    Function SumCellsByColor(rData As Range, cellRefColor As Range)
    Dim indRefColor As Long
    Dim cellCurrent As Range
    Dim sumRes

    Application.Volatile
    sumRes = 0
    indRefColor = cellRefColor.Cells(1, 1).Interior.Color
    For Each cellCurrent In rData
    If indRefColor = cellCurrent.Interior.Color Then
    sumRes = WorksheetFunction.Sum(cellCurrent, sumRes)
    End If
    Next cellCurrent

    SumCellsByColor = sumRes
    End Function

    Function CountCellsByFontColor(rData As Range, cellRefColor As Range) As Long
    Dim indRefColor As Long
    Dim cellCurrent As Range
    Dim cntRes As Long

    Application.Volatile
    cntRes = 0
    indRefColor = cellRefColor.Cells(1, 1).Font.Color
    For Each cellCurrent In rData
    If indRefColor = cellCurrent.Font.Color Then
    cntRes = cntRes + 1
    End If
    Next cellCurrent

    CountCellsByFontColor = cntRes
    End Function

    Function SumCellsByFontColor(rData As Range, cellRefColor As Range)
    Dim indRefColor As Long
    Dim cellCurrent As Range
    Dim sumRes

    Application.Volatile
    sumRes = 0
    indRefColor = cellRefColor.Cells(1, 1).Font.Color
    For Each cellCurrent In rData
    If indRefColor = cellCurrent.Font.Color Then
    sumRes = WorksheetFunction.Sum(cellCurrent, sumRes)
    End If
    Next cellCurrent

    SumCellsByFontColor = sumRes
    End Function
    Last edited by dineshiam; 07-19-2020 at 02:45 AM. Reason: Placement of points

  7. #7
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Looking to count status based on Cell color

    @dineshiam

    Thanks for posting the code.

    Please add the code in #6 between tags # according to the forumrules.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Count data based on color of cell with criteria
    By HaroonSid in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-16-2017, 04:26 AM
  2. Count based on color of cell
    By onelovesojah in forum Excel General
    Replies: 5
    Last Post: 01-12-2015, 03:09 PM
  3. [SOLVED] How to COUNT cell based on either COLOR or correct result?
    By Kagesen in forum Excel General
    Replies: 3
    Last Post: 05-12-2014, 12:40 AM
  4. Count cells based on cell color
    By vamshi57 in forum Excel General
    Replies: 3
    Last Post: 04-14-2014, 02:11 AM
  5. Count based on cell fill color
    By hmesler in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-29-2011, 01:01 PM
  6. Changing cell color based on count
    By mossman65 in forum Excel General
    Replies: 1
    Last Post: 01-28-2011, 09:37 PM
  7. macro: changing cell color based on count in cell
    By Vbort44 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-08-2008, 07:28 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1