+ Reply to Thread
Results 1 to 4 of 4

Sum/Count Cells by Font Color

  1. #1
    Registered User
    Join Date
    07-12-2014
    Location
    North Carolina
    MS-Off Ver
    Office 2007
    Posts
    79

    Sum/Count Cells by Font Color

    Hello,
    I've been at this for about two hours and can't figure it out.

    Here's what I'm trying to accomplish- I have items that are color coded (by font color, they cannot be color coded by background color)- I need to obtain both the count and sum of these times based on their font color.

    I've been trying to use this code (that I got from Ozgrid.com
    (Code)
    Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)

    Dim rCell As Range

    Dim lCol As Long

    Dim vResult


    lCol = rColor.Interior.ColorIndex

    If SUM = True Then

    For Each rCell In rRange

    If rCell.Interior.ColorIndex = lCol Then

    vResult = WorksheetFunction.SUM(rCell,vResult)

    End If

    Next rCell

    Else

    For Each rCell In rRange

    If rCell.Interior.ColorIndex = lCol Then

    vResult = 1 + vResult

    End If

    Next rCell

    End If

    ColorFunction = vResult

    End Function
    (/Code)

    I've been trying to use the above VBA code with these formulas:
    =ColorFunction($C$1,$A$1:$A$12,TRUE) (to get SUM)
    =ColorFunction($C$1,$A$1:$A$12,FALSE) (to get COUNT)

    I've tried changing the word "interior" to "font", with mixed results- it seems like each time I try it, I get accurate numbers for ONLY green font or ONLY Red font (the other color will contain numbers I can't make sense of). I've also tried replacing "FontIndex" with "Font".

    If it's easier, I'd be happy to code sum they by Index Code 10 (Green) and Index Code 3 (Red). There will be items that are black font, but I do not need totals from them.

    Does anyone know why this wouldn't work, or know a method I can use instead? I tried a method that used Application.Volatile, but it slowed down my code significantly.

    Thanks in advance,

    Chad

  2. #2
    Registered User
    Join Date
    07-12-2014
    Location
    North Carolina
    MS-Off Ver
    Office 2007
    Posts
    79

    Re: Sum/Count Cells by Font Color

    Yay! I figured it out on my own!

    I entered the VBA code I listed above and entered it twice- the second time I just added a "2" to each variable- i.e. "rCell2" "vResult2", then I changed each "interior" to "font"- now it's working perfectly!

    Thanks to anyone that starting helping me figure this out.

  3. #3
    Registered User
    Join Date
    03-16-2015
    Location
    Egypt
    MS-Off Ver
    2010
    Posts
    51

    Re: Sum/Count Cells by Font Color

    hi Chad Bateman
    try this function
    Regards
    mokhtar
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    07-12-2014
    Location
    North Carolina
    MS-Off Ver
    Office 2007
    Posts
    79

    Re: Sum/Count Cells by Font Color

    Actually for my immediate needs I figured it out, but I'm saving the code you provided as I'll probably need it later.

    Thanks!

+ 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. VBA Module counts background color, would like it to count font color
    By LawBeforeGrace in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-25-2013, 08:11 AM
  2. Replies: 2
    Last Post: 02-04-2013, 02:00 PM
  3. [SOLVED] Count cells that have specific font color
    By Wheelie686 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-19-2012, 08:24 PM
  4. Count by color font help
    By Greed in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-18-2011, 09:14 AM
  5. Count if font color..
    By Murph in forum Excel General
    Replies: 2
    Last Post: 08-15-2005, 05:45 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