Count by Color

smalik

Board Regular
Joined
Oct 26, 2006
Messages
186
Office Version
  1. 365
Platform
  1. Windows
Is there a way to count cells by a specific color?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
For example, I have a range of cells A1 through H1. However, only three cells are highlighted in Yellow. How do I count this by using a formula?

Do I need to know the code for the color? i,e., light yellow vs. dark yellow where do I find the code? Is that the HEX code?
 
Upvote 0
It can only be done using VBA. Formulae cannot see the colour of a cell.
 
Upvote 0
You cannot count cell color by formula... unless you are coloring the cells with a conditional formatting formula, then you could use the same formula conditions to count cells. Otherwise, you have to use VBA.
 
Upvote 0
You could use a custom LAMBDA function, i.e. to define a name (you can name it e.g. COLOR):

Excel Formula:
=LAMBDA(array,MAP(array,LAMBDA(a,GET.CELL(63,a))))

This will allow you to call your custom function, specifically to select a range of cells and return a list of corresponding numbers for different colors; then you could use this helper column as an input for another Excel function such as COUNTIFS or SUMIFS.
 
Upvote 0
You cannot count cell color by formula... unless you are coloring the cells with a conditional formatting formula, then you could use the same formula conditions to count cells. Otherwise, you have to use VBA.
I am coloring them using the conditional formatting. However, each column has a different condition. Some columns are highlighted because they are blank, and some are highlighted because they do not meeting the specific criteria for that field.
 
Upvote 0
You could use a custom LAMBDA function, i.e. to define a name (you can name it e.g. COLOR):

Excel Formula:
=LAMBDA(array,MAP(array,LAMBDA(a,GET.CELL(63,a))))

This will allow you to call your custom function, specifically to select a range of cells and return a list of corresponding numbers for different colors; then you could use this helper column as an input for another Excel function such as COUNTIFS or SUMIFS.
I am not familiar with VBA, Is this a VBA Code? how do I use it? Can I get an example using countifs? Thanks.
 
Upvote 0
Cf. the picture: 1) copy the formula to "Refers to:", 2) type COLOR in "Name:", 3) Hit OK; 4) type =COLOR in a selected cell and select the range of cells where you would to distinguish colors, 5) the formula should return an array of numbers corresponding to cell colors. 6) E.g. yellow color will be represented as 6 which you can in another standard formula (e.g. COUNTIFS all cells where there is 6 will represents all yellow cells). The only thing to remember is that it will not recalculate automatically when you change background color of a cell (you can address this by e.g. entering the cell and hitting Enter without changing anything).
 

Attachments

  • DN.png
    DN.png
    15.1 KB · Views: 22
Upvote 0

Forum statistics

Threads
1,221,577
Messages
6,160,609
Members
451,657
Latest member
Ang24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top