+ Reply to Thread
Results 1 to 14 of 14

Thread: Count font color sum will not auto calculate

  1. #1
    Forum Contributor
    Join Date
    07-15-2011
    Location
    Whitby, Canada
    MS-Off Ver
    Excel 2010
    Posts
    121

    Count font color sum will not auto calculate

    I have this formula to sum the cells with certain font colors that will not caluclate by itself unless under very few conditions:

    =CountFontColor(A3:A13,-4105)-COUNTIF(A3:A13,"")

    My problem is that I am creating this spreadsheet to be as easy to use as possible (users have little to no excel knowledge) and the cells that need to be counted are set to change color based on a conditional format - this conditional format is based on a range of cells in column B - which are drop-downs (to make it fool-proof for the user)

    So, the problem is that column A is pre-populated with names, column B has a drop down....if a certain 'absence code' is selected in column B, the corresponding name in column A will change color....but the total of my formula =CountFontColor(A3:A13,-4105)-COUNTIF(A3:A13,"") remains the same until I click on the cell and hit 'enter'. I can't have these users doing that so how do I get it to calculate by itself?

    Thanks
    Last edited by Greed; 07-21-2011 at 03:50 PM. Reason: Solved

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Count font color sum will not auto calculate

    Hello Greed,

    Since Excel 2003 and earlier does not have a native function to count font colors, this function must be a VBA macro, Yo can get it to recalculate when theever the worksheet is recalculated by adding the statement Application.Volatile to the beginning of the macro.

    Example
    Function CountFontColor(Rng As Range, ByVal FontColor As Long) As Long
      Application.Volatile
    
      'Other Code
    
    End Function
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    07-15-2011
    Location
    Whitby, Canada
    MS-Off Ver
    Excel 2010
    Posts
    121

    Re: Count font color sum will not auto calculate

    Hi Leith,

    Unfortunately, it doesn't seems to be working...not sure if I have done something wrong. Here is the code I have currently:
    Function GetFontColorIndex(pRange As Variant) As Integer
        Application.Volatile
        
        Set pRange = pRange.Areas(1)
    
        GetFontColorIndex = pRange.Cells(1, 1).Font.ColorIndex
    
    End Function
    
    Function CountFontColor(pRange As Variant, pIndex As Integer) As Integer
        
        Application.Volatile
    
        Dim LTestRange As Variant
        Dim i As Long, j As Long, m As Long, n As Long
        Dim LTotal As Integer
    
        Set pRange = pRange.Areas(1)
    
        LTotal = 0
    
        m = pRange.Rows.Count
        n = pRange.Columns.Count
        LTestRange = pRange.Value
    
        For i = 1 To m
            For j = 1 To n
                If pRange.Cells(i, j).Font.ColorIndex = pIndex Then
                    LTotal = LTotal + 1
                End If
            Next j
        Next i
    
        CountFontColor = LTotal
    
    End Function

    If I select a drop-down in column B and it changes the color of the name in column A, the total remains the same.

    Thanks -
    Last edited by Leith Ross; 07-21-2011 at 02:49 PM. Reason: Added Code Tags

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Count font color sum will not auto calculate

    Hello Greed,

    VBA can not count cell colors if they are set by Conditional Formatting.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Forum Contributor
    Join Date
    07-15-2011
    Location
    Whitby, Canada
    MS-Off Ver
    Excel 2010
    Posts
    121

    Re: Count font color sum will not auto calculate

    Ahhh, that explains it...any suggestions on how to count the blank cells + cells with certain text in them?

    thanks

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Count font color sum will not auto calculate

    Hello greed,

    You can use the worksheet function CountIf to return the count of cells in a range that match a given value.

    To count the blank cells
    Sub CellCount()
      
      Dim CellCnt As Long
      Dim Rng As Range
      
        Set Rng = ActiveSheet.Range("A1:A100")
        
        CellCnt = WorksheetFunction.CountIf(Rng, "AAAA")
        CellCnt =CellCnt + WorksheetFunction.CountIf(Rng, "")
        MsgBox "Cell count is " & CellCnt
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Forum Contributor
    Join Date
    07-15-2011
    Location
    Whitby, Canada
    MS-Off Ver
    Excel 2010
    Posts
    121

    Re: Count font color sum will not auto calculate

    Thanks so much!

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Count font color sum will not auto calculate

    Hello greed,

    Glad to help.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  9. #9
    Forum Contributor
    Join Date
    07-15-2011
    Location
    Whitby, Canada
    MS-Off Ver
    Excel 2010
    Posts
    121

    Re: Count font color sum will not auto calculate

    Hi Leith,
    If you are still around and able to help ...this function can't do quite what I need it to....I need a formula or something to enter in a series of 'totals' cells - 5 separate cells to count the blanks + the cells that have "AC, "AP" etc. for 5 different ranges
    Thanks

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Count font color sum will not auto calculate

    Hello Greed,

    In that case, you will need to a workbook for me.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  11. #11
    Forum Contributor
    Join Date
    07-15-2011
    Location
    Whitby, Canada
    MS-Off Ver
    Excel 2010
    Posts
    121

    Re: Count font color sum will not auto calculate

    attached- thanks
    cell A14 is my poor attempt....
    Attached Files Attached Files

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Count font color sum will not auto calculate

    Hello Greed,

    You just needed a couple of array formulas to do the job. Here is the first formula.
    =SUM(--(COUNTIF(B3:B13, G23:G28)))
    Enter using Ctrl+Shift+Enter
    Because your total cell is part of a merged cell, the cells must be unmerged before adding the formula. The formulas have been added to the attached workbook.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  13. #13
    Forum Contributor
    Join Date
    07-15-2011
    Location
    Whitby, Canada
    MS-Off Ver
    Excel 2010
    Posts
    121

    Re: Count font color sum will not auto calculate

    Super! I had to tack on a bit at the end to make it work (only count the names in black)
    =SUM(--(COUNTIF(B3:B13, G23:G28)))+COUNTIF(B3:B13, "")-COUNTIF(A3:A13, "")
    but I can't thank you enough....hopefully one day I'll get good enough to be able to help someone the way you helped me You're great!!
    Gillian

  14. #14
    Registered User
    Join Date
    09-06-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Count font color sum will not auto calculate

    Dear Leith,

    You seem like a color count hero ;-).
    I have a similar problem as Greed, it would be great if you could help me with it.

    Key points:
    1) Excel: I use Excel 2007, and have basic understanding of VBA
    2) Issue: I need Excel to count the number of cells that meet Criteria A (text), Criteria B (text) and Criteria C (red color).

    Question:
    I now however need to count the cells that meet Criteria A (text), Criteria B(text) AND are Red.

    I tried to do this with:
    =Countifs (range “column A”, Criteria A “text”, range “column B”, Criteria B “text”, range “column C”, Criteria C color red).

    For Criteria C I however do not know which formula to use to get the criteria “red cell”. I would not like to add additional columns, everything should be in one formula.
    I tried all, but nothing worked. I run the color module by Chip Pearson, but this gave an error message.

    Hope you’ll be able to provide me with the answer…

    Many thanks!

    Best regards,

    Alinda
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0