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
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 Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
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
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 Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Ahhh, that explains it...any suggestions on how to count the blank cells + cells with certain text in them?
thanks
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 Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Thanks so much!
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 Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
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
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 Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
attached- thanks
cell A14 is my poor attempt....
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)))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.
Enter using Ctrl+Shift+Enter
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 Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
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 meYou're great!!
Gillian
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks