+ Reply to Thread
Results 1 to 19 of 19

Count cells conditionally formatted by colour

  1. #1
    Registered User
    Join Date
    11-19-2017
    Location
    Oslo, Norway
    MS-Off Ver
    15.3
    Posts
    19

    Count cells conditionally formatted by colour

    I need a VBA function that count cells conditionally formatted by colour. I have three different colours; green, yellow and red, and I am using a formula to determine which cells to format. I have tried several functions found online, but every one of them return errors which I suspect is because I use non-standard colour codes, although I am not sure.

    Please see attached spreadsheet.
    Attached Files Attached Files
    Last edited by ilohyou; 08-03-2018 at 03:34 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: Count cells conditionally formatted by colour

    Sadly I don't think this is as easy as you'd expect. Excel/vba will not recognize the conditionally formatted color as the true color of the cell. E.g. try
    Please Login or Register  to view this content.
    and they won't match up. Otherwise, the code below would work fine. Maybe someone has another idea but the only way I can see of making this work is having a vba code that evaluates the conditional formatting criteria directly, and pastes the colour as the true colour of the cell.
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,047

    Re: Count cells conditionally formatted by colour

    See these threads.
    https://www.excelforum.com/excel-pro...nditional.html
    https://www.excelforum.com/excel-pro...by-colour.html

  4. #4
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: Count cells conditionally formatted by colour

    Wasn't aware of the .DisplayFormat trick thanks @ByteMarks. With that edit this will actually work then.
    Please Login or Register  to view this content.
    With the output in column "AR".
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,112

    Re: Count cells conditionally formatted by colour

    How about
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-19-2017
    Location
    Oslo, Norway
    MS-Off Ver
    15.3
    Posts
    19

    Re: Count cells conditionally formatted by colour

    It looks good! Is it possible to create a function where I can choose the desired colour and range to count?
    Last edited by ilohyou; 08-03-2018 at 11:12 AM.

  7. #7
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,112

    Re: Count cells conditionally formatted by colour

    Maybe
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-19-2017
    Location
    Oslo, Norway
    MS-Off Ver
    15.3
    Posts
    19

    Re: Count cells conditionally formatted by colour

    Sorry, I forgot to mention that I am new to VBA. How can I call the function from the worksheet?

  9. #9
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,112

    Re: Count cells conditionally formatted by colour

    I'm not sure that you can.
    I don't think you can use DisplayFormat inside a function.

  10. #10
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Count cells conditionally formatted by colour

    Why not use a formula to count the number of instances where the CF formula returns TRUE for each color?

  11. #11
    Registered User
    Join Date
    11-19-2017
    Location
    Oslo, Norway
    MS-Off Ver
    15.3
    Posts
    19

    Re: Count cells conditionally formatted by colour

    Quote Originally Posted by 63falcondude View Post
    Why not use a formula to count the number of instances where the CF formula returns TRUE for each color?
    I am trying to do it the way you are suggesting, but the solution does not seem obvious. My goal is to make a "+" if the majority of the cells within each 6x1 range is green, "o" if yellow, and "-" if red. The CF formulas are in the top right corner of the worksheet. If you can point me in any direction, it would be great. Otherwise, I might consider posting a new thread. Thank you anyway.

  12. #12
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Count cells conditionally formatted by colour

    I think that is absolutely possible. If you manually colored the cells, you would need VBA but since they are colored using Conditional Formatting, we can use those same rules in a formula.

    I'll have a go at it.

    Where would you like those "+", "o", or "-" marks to be located? What if there is a tie such as 3 green and 3 yellow?

  13. #13
    Registered User
    Join Date
    11-19-2017
    Location
    Oslo, Norway
    MS-Off Ver
    15.3
    Posts
    19

    Re: Count cells conditionally formatted by colour

    Thank you for helping! I have attached a new spreadsheet that shows where I want them located.

    If there are 3 green and 3 yellow, it should show "o". Similarly if 3 red and 3 yellow, or 2 green, 2 yellow and 2 red.
    Attached Files Attached Files
    Last edited by ilohyou; 08-03-2018 at 02:26 PM. Reason: Updated spreadsheet

  14. #14
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Count cells conditionally formatted by colour

    I am not suggesting that this is a solution, just showing how to count colors that were filled using Conditional Formatting.

    Let's take G19:G24 as an example. You can use formulas like these to count the # of red, yellow, and greens for each 6x1 range:

    r =SUMPRODUCT(--(ABS(E19:E24-$B19:$B24)>3*G19:G24))
    y =SUMPRODUCT((ABS(E19:E24-B19:B24)>2*G19:G24)*(ABS(E19:E24-B19:B24)<3*G19:G24))
    g =SUMPRODUCT(--(ABS(E19:E24-$B19:$B24)<2*G19:G24))

    Getting on to the question at hand...

    A question that I have is which 6x1 ranges should we be looking at? Let's say for cell AR14 (in the workbook from post #13).
    I see that cell AR14 is for ContD (S=90) and M=10,000. Which 6x1 range should this look at? G5:G10 or J5:J10?

  15. #15
    Registered User
    Join Date
    11-19-2017
    Location
    Oslo, Norway
    MS-Off Ver
    15.3
    Posts
    19

    Re: Count cells conditionally formatted by colour

    Great! I will look into the formulas. To answer your question, I just updated the spreadsheet in the previous post with separate columns for OLS, tikh and CART. CART has only one cell, so it should show the result for that specific cell.

    You don't need to do all of them, but if you could show me how it works it would be great!

  16. #16
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Count cells conditionally formatted by colour

    I think this is going to be step 1. See columns AQ:AV in the following attachment.

    This gets the color data in a readable format.
    This is the most time consuming part but once this is done, part 2 will be creating a single formula to be placed in AZ14 that can be dragged across and down.

    It's cumbersome (but not impossible) because of the layout of the data.

    That's all the time that I have today though. Enjoy your weekend!
    Attached Files Attached Files

  17. #17
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Count cells conditionally formatted by colour

    Okay, here would be step 2. All that you have to do is finish the table in columns AQ:AV and then adjust the ranges of the formula in AZ14.

    Once you finish the table, the N/A's will go away.

    See attachment.
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    11-19-2017
    Location
    Oslo, Norway
    MS-Off Ver
    15.3
    Posts
    19

    Re: Count cells conditionally formatted by colour

    I have been trying different ways to solve this problem for most of my day, but with your help I will finally be able to finish it. Thank you very much for your effort!

  19. #19
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Count cells conditionally formatted by colour

    You're welcome. Happy to help.

    Thanks for the rep!

+ 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] VBA to copy cells if other cells within row are conditionally formatted colour
    By Whitethorn in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 05-08-2018, 11:53 AM
  2. [SOLVED] How to count conditionally formatted font (red) cells and cell colour
    By Nampara in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-01-2018, 04:48 PM
  3. Count Colour Cells (Conditionally Formatted)
    By fastcar in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-31-2017, 03:28 PM
  4. UDF to Count Conditionally formatted cells by colour
    By ozzy_q in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 10-06-2013, 09:00 AM
  5. [SOLVED] How do you copy only those cells conditionally formatted to a certain colour?
    By strud in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-09-2013, 05:03 AM
  6. [SOLVED] Sum of conditionally formatted cells by colour
    By codeyl5 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2012, 09:42 AM
  7. Counting cells conditionally formatted, by colour
    By edwar368 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2011, 05:30 PM

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