+ Reply to Thread
Results 1 to 4 of 4

Count number only if cell is background filled

Hybrid View

  1. #1
    Registered User
    Join Date
    04-25-2013
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Count number only if cell is background filled

    Hi

    Hope someone can help.

    I need a formula to count the number of times a number appears in a background filled cell, ignoring the occasions when it appears in cells with no background fill.
    Say the number is to be entered in cell T3, and the range to examine is L6:EM179, and the cell Colour Index is 37 (Dark Blue in Excel 2010), I’ve tried the following array formula:

    {=COUNT(IF(GetColor(L6:EM179)=37,IF(L6:EM179=T3,1,””),””))}

    Where GetColor is set up as a VBA User Defined Function using the following code cribbed off the Internet:

    Function GetColor(Mycell As Range)
    GetColor = Mycell.Interior.ColorIndex
    End Function

    Unfortunately, this doesn’t appear to work, as it just returns a zero result.

    Any help would be greatly appreciated.

    Thanks

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

    Re: Count number only if cell is background filled

    The UDF's are not automatically running as Excel works it's way through the array so you end up with 0.

    Best bet is to set up a second sheet and in the same range set up a range of cells with
    =GetColor(sheet1!L6) (for example)
    Then you can use COUNTIFS($L$6:$EM$179, $T$3, Sheet2!$L$6:$EM$179, 37)
    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

  3. #3
    Registered User
    Join Date
    04-25-2013
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Count number only if cell is background filled

    Thanks ChemistB

    I'll check out your suggestion when I'm back at work and can access my spreadsheet!

    Cheers

  4. #4
    Registered User
    Join Date
    04-25-2013
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Count number only if cell is background filled

    Had a chance now to follow your advice, and it seems to work great, although I do have to perform a Ctrl+Alt+F9 every time I change a colour to get it to re-calculate.

    Thanks for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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