Monday 6 August 2012

How to count cells coloured by conditional format in Excel

Another non moodle post.  C'est la vie.

Quite a few questions pop up on Google saying they have a spreadsheet that uses conditional formatting to colour cells and they want to be able to count how many cells of a certain colour they have.  All the answers seem to point to this post by C Pearson who has an answer but it's not super obvious what to do with it.

If your spreadsheet press Alt and F11 to open the visual basic editor.  This allows you to add function to Excel.  In the left hand column right click the bold heading, it should say VBA Project(name of your spreadsheet).  Go to Insert > Module.

In the window that opens copy and paste the function code C Pearson provides and click the save icon. Then do the same right click, Insert > Module and do the next block of code. You need to add the Active Conditioning one and then whichever of the others you think would be useful to you.  I did all of them so I could try them out and the used CountOfCF.

So once you've added all the functions, use the formula:

=CountOfCF(C11:S15,3)

The green numbers are the range of cells you are looking at and the red number is the number that corresponds to the colour you're counting.  For me this number is three because it is the third condition in the conditional formatting.

And there you have it, counting conditionally formatted cells.

No comments:

Post a Comment

Comment