Closed Thread
Results 1 to 10 of 10

Counting Conditionally Formatted Coloured Cells

  1. #1
    Registered User
    Join Date
    03-20-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    5

    Counting Conditionally Formatted Coloured Cells

    Hi

    SUMMARY
    I am looking to count only cells which have been conditionally formatted too little success.


    BACKGROUND
    I have been working on a worksheet (attached) in Excel 2007 which is looking to show multiple cases and payments on a month-by-month basis.

    The first step was to only show the 'active' periods of each case, which I managed through conditional formatting, the CF formula is:

    =AND($F6>H$5,$E6<I$5)

    E6 is the case Start Date
    F6 is the case End Date
    H5 is month 1 (e.g. May 2013)
    I5 is month 2 (e.g. Jun 2013)

    When applied (to cases with dates), the 'active' periods are highlighted in blue (37, R:153/G:204/B:255)

    My next step was to then calculate the monthly income (the figure will differ for each case, but fixed across the period of each case) located in column D. I then copied this across the entire spreadsheet (=$D#). Unfortunately doing a sum to count the column would count all cells, and not those that which have been CF. In the attached worksheet, the text has been conditionally formatted to show up as black, otherwise the text is white.

    I thus began looking around for ways to count the content of cells that have been conditionally formatted to a certain colour. I have tried several methods (from across the web, and on this forum), and have come to the conclusion that the SUMBYCOLORINDEX method from http://www.cpearson.com/excel/CFColors.htm, but when I put in the following formula in row 3 (highlighted in yellow only to draw attention):

    =SUMBYCFCOLORINDEX(H6:H55,37)

    H6:H55 is the column of payments
    37 is the colour (blue, 37, R:153/G:204/B:255, http://dmcritchie.mvps.org/excel/colors.htm) of the CF cells

    I get a #NAME? error despite having Chip Pearson’s VB script active. In row 2 above I have done a quick count to show what the row 3 column CF sums should come to.

    For some reason I am unable to attach any files to this thread (either *.xlsm, *.xlsx, zip or .jpg (I get a 407 error?), so I have uploaded a picture here:

    A screenshot of the worksheet and script is visible here: http://i4.minus.com/iJmIaE1zx0LsW.jpg


    CONCLUSION
    I would be most grateful if anyone could provide me with assistance in solving this dilemma.
    Last edited by Tiraenus; 03-21-2013 at 08:07 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,879

    Re: Counting Conditionally Formatted Coloured Cells

    Why not count the cells based upon the condition that makes them a certain color, using the countif function.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    03-20-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Counting Conditionally Formatted Coloured Cells

    Quote Originally Posted by alansidman View Post
    Why not count the cells based upon the condition that makes them a certain color, using the countif function.
    Hi Alan

    Thanks for the response, in this example where the conditional formatting formula is =AND($F6>H$5,$E6<I$5), and the conditional formatting colour is 37 (R:153/G:204/B:255), what would be the COUNTIF formula?

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Counting Conditionally Formatted Coloured Cells

    I agree with Alan, but am not sure based on the picture how you are summing (by column?)

    As to why you're getting #Name, I believe it's because in your UDF you are referencing another function "ColorIndexofCF" You need to add that code to the module too.

    Please Login or Register  to view this content.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Registered User
    Join Date
    03-20-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Counting Conditionally Formatted Coloured Cells

    ChemistB - The cells in blue are due to the conditional formatting, and I was looking to sum only these cells. So for instance in I3 (Jun-13), the figure should be £120.00 because only two cells are highlighted (I6 + I9).

    A simple SUM calculation of the column would however show up as £353.00 (as the blank boxes actually contain the figure from column D but are in white text).

    I have added the code you have provided into VB, but still get the same error.

  6. #6
    Registered User
    Join Date
    03-20-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Counting Conditionally Formatted Coloured Cells

    I have managed to upload the file in question

    Example.xlsm (25 KB)
    https://mega.co.nz/#!dxFjWbRK!JViUrk..._qKyAW0M8icnwE

  7. #7
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Counting Conditionally Formatted Coloured Cells

    =SUMIFS(I$:6:I$50, $E$6:$E$50,"<"& I$5, $F$6:$F$50, ">"&H$5)
    Does that work for you?

  8. #8
    Registered User
    Join Date
    03-20-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Counting Conditionally Formatted Coloured Cells

    It does! <does a little jig around the office>.

    Excellent. Thanks for the help, I am eternally grateful!

  9. #9
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Counting Conditionally Formatted Coloured Cells

    Glad it worked.

  10. #10
    Registered User
    Join Date
    04-23-2018
    Location
    MALAYSIA
    MS-Off Ver
    MS EXCEL 2016
    Posts
    3

    Post Re: Counting Conditionally Formatted Coloured Cells

    Hi,

    Could you help me in counting the conditional formatting colored cells? I cannot count it properly.. I want to count the yellow and red colored cell for every description involved. The formula conditional formatting that I'm use is, format cell that contain. Yellow color cell for the value below low value and red color cell for the value that are above high cell. But the cell cannot be counted using normal way..

    Tq.

  11. #11
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,879

    Re: Counting Conditionally Formatted Coloured Cells

    @Ogy Ramly

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

Closed Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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