09-07-2019 03:25 PM - edited 09-09-2019 10:34 AM
09-19-2019 12:22 AM
Hi! I came across to this thread coz i was looking for an answer to my problem. And found that you posted one for "
However, what I want is to count all cells with red font color in a range but the FONT COLOR was based on the conditional formatting.
Example: range is A1:A1000 then the formatting I made was to turn DUPLICATE ENTRIES into a RED FONT COLOR. regardless of the text content. if apple and banana were duplicated twice. the result should give me NOT 2 BUT 4. Please help me.
Thanks in advance!
09-26-2019 11:58 AM
Hi @Jamil Mohammad,
Could you please look into a file attached? I am trying to count CF colored cells in "SJA racks" tab.
Getting "0" all the time. I ahve tried GetColorCount and COUNTConditionColorCells = same result "0".
What am I missing?
Thanks in advance for looking into this.
09-28-2019 05:43 PM
No need to overkill it with UDF. you can use built-in Excel formula to get what you need.
simply put this formula in M6 cell of SJA racks sheet and copy it down up to cell M51.
see also in the attached
09-28-2019 05:51 PM
09-28-2019 06:37 PM
you do not need UDF for this, you can accomplish the same with this formula
also see it in the attached workbook.
09-29-2019 11:51 AM
Hi Jamil, this formula works great except when all the cells in an array are blank. If all the cells in an array are blank then they are all equal, so it counts each as the "max". I've been searching for the possibility of using an IF to check if cell is blank, but not finding anything that suits my spreadsheet. How can I get around this?
Thank you again for your assistance in this. I'm not a strong user of Excel so need some help from time to time. And your expertise in invaluable!!
10-02-2019 02:23 AM
I read all your posts and appreciate all the comments from you and the other users.
But (there is always a but) I can't understand, why I am getting #Value! error.
So I have a couple of questions for you:
1. How I can create an applies to conditional format per row using the format painter button? I watch that in your video, but doesn't work for me:
At row five I created a conditional format =C5:L5
Each time I press enter (OK), it cames to =$C$5:$L$5
And if I use the format painter to copy to the remain rows it will be like this =$C$6:$L$32
When should be like: C6:L6, then C7:L7 ...
2. The count conditional formatting cell per color isn't working (O5)
Thanks for your support
10-02-2019 04:48 AM
I have revised the formula to take care of the blanks.
please see attached.
10-02-2019 05:13 AM
Hi, I checked your file. the UDF will not work this sort of range. because your conditional range is not within the range.
I also did not understand why your conditional formatting rule starts from C6 while the data is from C5.
I have put a formula in the attached file that shows how you can count the range of cells that meets the criteria within another range. see if you can work that out.
10-02-2019 07:57 AM
Once again thank you Jamil! Your help has been invaluable. The changes you've made work perfectly. I've attached a copy of the spreadsheet end result, in case you were curious. Also for anyone who might find themselves with the same issues.
Many thanks to you my friend!!
10-04-2019 04:03 AM
Thanks for your comments!
I will explain that file:
>In a company, workers use the national lottery to play a game (like bingo).
>Each week the lottery has 2 contests (C42:G73) and each contest 5 numbers;
> The first worker C5:L32 to complete all his number (per row) will win all the money;
>There is a conditional format to paint as red (when) the worker hit the number;
The person who is controlling this “social enterprise game” counts (cell by cell, without using a form or a macro) the number of whites, to know how many missing numbers each worker has.
I am trying to replace the “manual counting” with your script, we wish to count the missing numbers (white or without conditional format) = like column M.
11-04-2019 04:27 AM
You can use this formula =SUMPRODUCT(1-(COUNTIFS($C$42:$G$10010,C5:L5)>0))
please see attached file.
11-21-2019 12:16 AM
I've been trying to adapt your code to count cells in a range that have fonts that are conditionally formatted (bold-red or bold-green). The cells use a formula to decide the condition. I found this simple function code below but it looks for font color rather than conditional formatted font color. Any help you can provide would be awesome.
Function CountColour(rng As Range, clr As Range)
Dim c As Range
For Each c In rng
If c.Font.Color = clr.Font.Color Then
CountColour = CountColour + 1
11-21-2019 12:14 PM
12-21-2019 03:44 PM
I went through all the discussion here and yet I can make my excel sheet to work with this code, I just get 0.
Can you have a look at the data.
I am attaching the macro-enable sheet and the one without it.
I want to have a summary table of how many people have the training completed, about to expired, experied, and never been taken.
12-27-2019 03:22 AM
Hi, no need for UDF. I have build formula to do the calculation.
the word TODAY in the formulas are a named range.
please see attached.
01-05-2020 08:05 AM
Hi @Jamil Mohammad.
Thanks for your help, it is working now, I don't quite understand what was the reason for this error.
Another thing is that I just noticed my color coded formating is not working as I expected, I set the cell date within 45 days from today to change to Orange color which are the trainings about to expired. and if the date in the cell is less or equal to today´s date should turn into red but it is not working, it is happening to cells over 45 days I think.
I also noticed that if the cell changed to orange is it not counting yet in the summary, can you have a look one more time and thanks in advance.
By the way happy new year from Argentina.
01-06-2020 05:47 AM
02-18-2020 07:41 PM
Hi Jamil, Your code is great. Unfortunately it didnt work like I intend it to do, I have used it in my gantt chart and I want to count the colored cells in a week. See my Dummy. Thanks
02-24-2020 05:18 AM
04-11-2020 06:49 PM
I tried this code, but it only works for the first row. It doesn't work on the rest of the rows. What am I doing wrong? Please see attached.
04-15-2020 04:37 AM - edited 04-15-2020 04:38 AM
Hi, It did not work because, the UDF is range sensitive. the range set in Conditional formatting and the range used int he UDF must match. Your UDF ranges were looking to for each row and the CF was set for the entire range. I changed the CF range to single row, then used paint brush to create same CF for each row and then the UDF calculation started to work.
I have attached the workbook, as well as a animated video on how did I do it.
04-16-2020 02:34 AM
@Jamil Mohammad How to use this function to row. I need to pull the formula and count the co;ored formatted cells in each row
04-16-2020 03:36 AM
Please see my answer which I replied to Kalpesh64 link here https://techcommunity.microsoft.com/t5/excel/how-to-count-and-sum-quot-condtional-formatting-quot-ce...
There I have shown how you can do it per row. file is attached there and also the GIF animated recorded video.
04-16-2020 02:02 PM
@Jamil Mohammad Thank you but can you show me the code which you use to get this formula
04-16-2020 02:40 PM
@Jamil Mohammad Dear Mr. Jamil : I tried to use on my sheet but it give me #VALUE!, I attached the sheet. I used 2 formula ( in Cell AN2 and AN5 )for Formatting the cells . Please can you help me get the formula and show me the code.
04-21-2020 06:16 AM
@Jamil Mohammad I'm attaching a TEST file. Please direct your attention to cells: J5:J8, Column 'T', Column 'U', cells 'Z13:Z15' and 'AA13:AA15'.
What I'm trying to achieve is for UDF to calculate/ COUNT the perspective colored cells in Column U accordingly; then report that number in Cells AA13, AA14 and AA15. I then will copy/link that number or cell to my LEGEND located at Cell: R62 - R65. Column U is the Color Indicator Column. Obviously the color will change based on the average time per student. I want to count those results appropriately to automatically convert a Weekly Percentage. After applying your code, I still can't get the code to talk properly within the document. Please Help!
04-21-2020 03:09 PM
Perhaps, you did not read my earlier posts. I have mentioned that the range used in the UDF must be a mirror of the range in the conditional formatting. I can see from your example file that you have applied multiple range in the single rule of conditional formatting and also it is vertical by column and yet the UDF is using single range of single horizontal row. so the ranges do not match that is why you get the error.
04-21-2020 03:34 PM
Hi, I looked at your file. there are many overlapping conditional formatting rules which you have set. for example the color yellow is overrulled by color red. so the true count of the yellow cells are distorted.
Perhaps, you are overkilling this by using this advanced udf for such calculation that can be done using built-in array formulas. for example you count of yellow cells can be achieved using the =SUMPRODUCT((--(T4:T55<>""))*(T4:T55<J6)*(T4:T55>J7)) the first part of the array excludes blank cells and second part of array is exactly as per your conditional formatting and the third part of array is not to overrule the second part. as it is now in the conditional formatting. try to calculate it using the built in formula as i have given example for one of the items in the list.
04-21-2020 08:54 PM
@Jamil Mohammad I already get the code running on my log sheet , but I am getting #VALUE! then If I select the formula and press Enter it will run and if I drag it below it will give correct answer only for 10 rows below and below this the formula showing #VALUE! then need from the formula in the last row which showing correct result to drag below and again it will give correct answer in the below 10 rows and the other row will show #VALUE!.
Is their any way to let the formula properly work for all the rows as I drag it below ?
Attached the file I am working with.
04-21-2020 10:03 PM
@Jamil Mohammad Thanks for the quick reply. I implemented the formula you provide and it returned a number higher than what was expected. All I did was paste the formula in a blank cell and it returned "29" as a result. Let me know if I need to reorder my CF rules or try another strategy. How do you feel about perhaps counting by color code? Will this emit the same issue?
04-22-2020 11:54 PM
04-23-2020 05:57 AM
In your excel file, you had a pre set value of 20 for yellow color (Below 30 minutes; more Login Time needed.) I placed the formula =SUMPRODUCT((--(T4:T55<>""))*(T4:T55<J6)*(T4:T55>J7)) there and it returned 20. similarly, for other conditions, you can specify what should be the rule to count and using SUMPRODUCT function you can easily get the correct count.
Please see attached workbook the example of yellow color is shown with formula there in cell R63
04-23-2020 06:02 AM
I run a small test and I see that there are a lots of circular references in formulas inside conditional formatting rules. and each conditional formatting rules has multiple logical test and it overwhelm the calculation engine. Unfortunately, I do not have time to build from scratch a neat table for you, as it takes a lot of time. If I was you, I would not use nested IF inside the Conditional formatting rules and instead use helper column, this way you avoid too much calculation and circular reference issues.
04-23-2020 06:54 AM
I assume this is not question related to captioned title of this thread. So, I wouldn't know why it does not work. As i have not seen the file. try to see if you have any broken link among the links. It could be the issue similar to the issue report here
see the answer from Ashish.
05-08-2020 04:32 PM
Hi Jamil, thanks for your quick response.
I am trying to count the cells in column P in each different section and total these to a specific cell- these have been condition formatted to change colour depending on the values that are put into them, which are summed by the Moulds & Yeasts Columns (Q&R)- for example, I want the total of green cells within P9-18 to be totalled inside C51 and then the orange and red cells from P9-18 in C52 and C53, but I want C51, 52, and 53 to be able to update when changes occur in P9-18 and the colours change. I have managed to add a VBA code where the totals can recognise the colours but I cannot get them to update when the colours change from their value.
I have attached a copy of the workbook without the macro enabled as it was the only way the site would allow me to send it. hope this helps.
Many thanks for your help!
05-14-2020 07:51 PM
What you are after is possible and this UDF can do that.
If you read my earlier messages in this thread, you will notice that I mentioned that for this UDF to work, the conditional formatting rule should be creating using the option "use a formula to determine which cell to format"
to demonstrate, I have changed the rules of conditional formatting for range P9-18 and replaced it with formula. I replaced the rule, between 0 to 9 with =AND(ISNUMBER(P9),LEN(P9)=1) and also the other two colors as you can see it in the attached file.
then I placed the UDF as an example in the cell C51 which correctly returns the value. given this example, you can replicate this for other ranges/cells.
plz see attached file.
by Lucky7423 on May 30, 2020
by cuong on May 27, 2020
by Ingeborg Hawighorst on May 13, 2020