+ Reply to Thread
Results 1 to 4 of 4

Counting Cells by font color problem

Hybrid View

  1. #1
    Registered User
    Join Date
    04-09-2007
    Posts
    13

    Counting Cells by font color problem

    I found this code online that counts the number of cells in a certain range with a specified font color. (Each of my cells have either red or black text, and I wanted to sum the number of cells with black text, and the number of cells with red text.) The code can be found here:

    http://www.xldynamic.com/source/xld.ColourCounter.html

    I thought I was using the code incorrectly since I'm fairly new to excel and the results returned were way off. However, it appears that for some reason it is counting cells with no text. I checked this by changing the default color of the blank cells within the range to some other color (not red or black). I then got accurate results.

    Does anybody have any idea on why this is happening, or how I can prevent it. Having to assign a font color to the blank cells greatly decreases the usefulness of this code.

    Thanks

    Mark

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    What formula you using

    As the site mentions defauly is cell colour.

    Determines cell colour (interior) or text colour (font)
    ' Default is cell colour
    Need to use a formula like (Note the true for font instead of cell)

    =SUMPRODUCT(--(ColorIndex(A1:A100,TRUE)=3))

    Also you have to press F9 to recalc which also may look like it's not working

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Valued Forum Contributor
    Join Date
    04-11-2006
    Posts
    407
    How does this work for you?
    =SUMPRODUCT(--(ColorIndex(A1:A100,TRUE)=3),--(A1:A100<>""))

  4. #4
    Registered User
    Join Date
    04-09-2007
    Posts
    13
    Quote Originally Posted by Ikaabod
    How does this work for you?
    =SUMPRODUCT(--(ColorIndex(A1:A100,TRUE)=3),--(A1:A100<>""))

    This worked exactly as I need it to. Thanks very much

+ 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