+ Reply to Thread
Results 1 to 9 of 9

Count Number of times Color appears in row

  1. #1
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Count Number of times Color appears in row

    Hey all, me again

    I am trying to get a COUNT for the number of times a color appears in a row (well in cells in a range in a column) using this code:

    Please Login or Register  to view this content.
    Then using it in a cell like
    Please Login or Register  to view this content.

    The issue I am having is
    a) It doesn't update automatically, seems I have to click in that cell, F2 to go in the formula bar and press enter to recount).
    b) It doesn't seem to recognize colors set by conditional formatting, which mean sit doesn't work for me. I need it to see conditional formatting not just manual formatting.

    Any ideas?

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Count Number of times Color appears in row

    Quote Originally Posted by NewYears1978 View Post
    a) It doesn't update automatically, seems I have to click in that cell, F2 to go in the formula bar and press enter to recount).
    That is because changing colours does not trigger a recalculation. As a bare minimum, you need to add Application.Volatile at the start of the function, but that will only make it recalculate when the workbook does- which a colour change will not cause on its own.

    b) It doesn't seem to recognize colors set by conditional formatting, which mean sit doesn't work for me. I need it to see conditional formatting not just manual formatting.
    You will have to evaluate the conditions in the function, or use a subroutine that can check the DisplayFormat property of the cells (which a UDF cannot). Note that that property is only available from 2010 onwards so would not work for 2003.

    Any ideas?
    Yes, but probably not one you will like. Don't try to use colours as data. It's not something Excel is good at.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Count Number of times Color appears in row

    This code should recognize the Conditional Format generated colors:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Count Number of times Color appears in row

    Displayformat does not work in a UDF called from a cell.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Count Number of times Color appears in row

    Displayformat does not work in a UDF called from a cell.
    Hi xlnitwit,

    It worked for me

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Count Number of times Color appears in row

    Can you post the workbook? I’d love to see that.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Count Number of times Color appears in row

    It worked until I tried to save it

    Does that make sense??

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Count Number of times Color appears in row

    No, but stranger things have happened in VBA!

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Count Number of times Color appears in row

    Yeah - I can make it work temporarily:

    Please Login or Register  to view this content.

+ 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. VB To count the number of times a Highlighted Color appears
    By liamfrancis2013 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-06-2016, 10:32 AM
  2. [SOLVED] Count the number of times an A appears 5 or more times consecutively
    By CCook310 in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 10-02-2013, 04:02 PM
  3. Count number of times 3,appears
    By ORIELSON in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-06-2013, 08:58 AM
  4. How to count the number of times something appears?
    By Ipinho100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2012, 08:08 AM
  5. How to count the number of times something appears?
    By Ipinho100 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-28-2012, 01:13 PM
  6. Count number of times n/s appears
    By hugrl in forum Excel General
    Replies: 2
    Last Post: 11-21-2009, 08:57 AM
  7. [SOLVED] Count Number of Times Something appears
    By Mark B in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-29-2005, 04:40 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