+ Reply to Thread
Results 1 to 18 of 18

Count Conditionally Formatted Cells (Visible Only)

  1. #1
    Registered User
    Join Date
    09-25-2015
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    29

    Count Conditionally Formatted Cells (Visible Only)

    Hi there! Macro beginner here.

    I have a column where I count the number of conditionally cells formatted to be red as below:
    Please Login or Register  to view this content.

    All my data is laid out by # or % for each period. However, I have a button which will hide the % columns if you wish to only look at the numbers only. However, once the % columns are hidden, the macro is still counting the hidden conditionally formatted. How do I get it to only calculate visible cells?
    Last edited by LJenny; 09-25-2015 at 01:48 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Count Conditionally Formatted Cells (Visible Only)

    Try something like this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    09-25-2015
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    29

    Re: Count Conditionally Formatted Cells (Visible Only)

    EDIT: Hm now seems to not be affecting it at all.
    Last edited by LJenny; 09-25-2015 at 11:56 AM.

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Count Conditionally Formatted Cells (Visible Only)

    If you're just looking to count any visible cells that have conditional formatting,
    try this example:

    Please Login or Register  to view this content.
    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Count Conditionally Formatted Cells (Visible Only)

    Double check for a typo. It shouldn't give that error unless it was entered incorrectly.

    Otherwise, can post exactly your entire code. We may be talking past each other.

  6. #6
    Registered User
    Join Date
    09-25-2015
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    29

    Re: Count Conditionally Formatted Cells (Visible Only)

    Quote Originally Posted by AlphaFrog View Post
    Double check for a typo. It shouldn't give that error unless it was entered incorrectly.

    Otherwise, can post exactly your entire code. We may be talking past each other.
    I've updated my original post to include the entire code. Since adding it, it seems to not have made a difference.

    Quote Originally Posted by Ron Coderre View Post
    If you're just looking to count any visible cells that have conditional formatting,
    try this example:

    Please Login or Register  to view this content.
    Is that something you can work with?
    Hm do I just add that to the code? Sorry I'm very new.
    Last edited by LJenny; 09-25-2015 at 12:04 PM.

  7. #7
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Count Conditionally Formatted Cells (Visible Only)

    Like I mentioned...it's just an example to play with.
    Instead of starting with the UsedRange, use a row reference:
    Please Login or Register  to view this content.
    The message box is just to let you know what the result is

  8. #8
    Registered User
    Join Date
    09-25-2015
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    29

    Re: Count Conditionally Formatted Cells (Visible Only)

    There are 85 instances of the count in the report, I have a column dedicated to it so the message box would not work.

    I need a usable function I can just apply to each team I need to calculate this for, I am not sure if that is the case here because this is literally my first time using macros with no VBA experience at all so sorry about the newbie-ness.

  9. #9
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Count Conditionally Formatted Cells (Visible Only)

    Ok...I understand. We all had to start somewhere when learning VBA.

    Try this User Defined Function (UDF)
    Please Login or Register  to view this content.
    In your worksheet, if you wanted to count the number of visible cells with conditional formatting in H5:P5
    you'd use that UDF this way:
    Please Login or Register  to view this content.
    Is that something you can work with?

  10. #10
    Registered User
    Join Date
    09-25-2015
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    29

    Re: Count Conditionally Formatted Cells (Visible Only)

    Quote Originally Posted by Ron Coderre View Post
    Ok...I understand. We all had to start somewhere when learning VBA.

    Try this User Defined Function (UDF)
    Please Login or Register  to view this content.
    In your worksheet, if you wanted to count the number of visible cells with conditional formatting in H5:P5
    you'd use that UDF this way:
    Please Login or Register  to view this content.
    Is that something you can work with?
    This is good! It is picking up on the hidden vs not hidden.

    However, it's counting all of the cells. I only wish to count cells which are coloured red due to conditional formatting.

  11. #11
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Count Conditionally Formatted Cells (Visible Only)

    I believe this code will work...as long as you are using Excel 2003 (it crashes on any version after 2003)

    Please Login or Register  to view this content.
    Does that help?

  12. #12
    Registered User
    Join Date
    09-25-2015
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    29

    Re: Count Conditionally Formatted Cells (Visible Only)

    It doesn't appear to be working.. only giving me 0 values for every row now.
    Last edited by LJenny; 09-25-2015 at 03:10 PM.

  13. #13
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Count Conditionally Formatted Cells (Visible Only)

    I wish I could test it...but, I haven't had Excel 2003 on a computer for several years.
    Perhaps someone else could chime in?

    Meanwhile:
    Check if the cCell.DisplayFormat.Interior.Color = 255
    • Select a CF cell with the red color
    • ALT+F11....to see the VBA editor
    • In the immediate window
    ...type this: ? ActiveCell.DisplayFormat.Interior.Color
    ...Press ENTER
    What number displays?

  14. #14
    Registered User
    Join Date
    09-25-2015
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    29

    Re: Count Conditionally Formatted Cells (Visible Only)

    I typed it right into one of my macros windows, which was what was open on the VBA editor.

    Pressed enter, it now says:
    Print ActiveCell.DisplayFormat.Interior.Color
    and doesn't do anything else.

    I selected the default red color that is available, it really should just be red (255,0,0).
    Last edited by LJenny; 09-25-2015 at 03:10 PM.

  15. #15
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Count Conditionally Formatted Cells (Visible Only)

    If you don't see the Immediate Window
    • View....select Immediate Window

    Then
    • Select one of the CF cells
    • Enter this in that window (beginning with the question mark): ? ActiveCell.DisplayFormat.Interior.Color
    • Press ENTER

    What happens?

  16. #16
    Registered User
    Join Date
    09-25-2015
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    29

    Re: Count Conditionally Formatted Cells (Visible Only)

    Run-time error '438'
    Object doesn't support this property or method.

  17. #17
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Count Conditionally Formatted Cells (Visible Only)

    In that case, you'd need to use code that basically mimics the CF rule for each cell in the referenced range and makes a tally.
    Seems like it might be an awful lot of work for minimal benefit. You might consider using a regular Excel formula to run the test(s) and return the count.

  18. #18
    Registered User
    Join Date
    09-25-2015
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    29

    Re: Count Conditionally Formatted Cells (Visible Only)

    Ah darn. Alright, thanks so much for all the help!

+ 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. Count conditionally formatted cells in excel
    By katiejessop in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-17-2013, 11:19 AM
  2. [SOLVED] How To Count Conditionally Formatted Cells
    By ScotyB in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-16-2013, 07:51 PM
  3. 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
  4. [SOLVED] count conditionally formatted cells
    By littlefoot in forum Excel General
    Replies: 5
    Last Post: 07-12-2012, 08:40 AM
  5. How to count cell which are conditionally formatted?
    By parekhharsh_j in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-12-2011, 02:53 PM
  6. Replies: 1
    Last Post: 08-26-2011, 09:57 AM
  7. Replies: 1
    Last Post: 08-02-2006, 10:45 AM

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