0% found this document useful (0 votes)
453 views

How To Count and Sum Cells Based On Background Color in Excel

Uploaded by

TinusAppelgryn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
453 views

How To Count and Sum Cells Based On Background Color in Excel

Uploaded by

TinusAppelgryn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

 ExtendOffice (https://www.extendoffice.

com)

Excel Tips Excel Functions Excel Formulas Word Tips


(/excel.html) (/excel/functions.html) (/excel/formulas.html) (/documents/word.html)

Outlook Tips
(/documents/outlook.html)

How To Count And Sum Cells Based On Background Color


In Excel?
Supposing you have a range of cells with different background colors, such as red, green, blue and
so on, but now you need to count how many cells in that range have a certain background color
and sum the colored cells with the same certain color. In Excel, there is no direct formula to
calculate Sum and Count of color cells, here I will introduce you some ways to solve this problem.

Count and Sum cells based on specific fill color by Filter and SUBTOTAL
Count and Sum cells based on specific fill color by GET.CELL function
Count and sum cells based on specific fill color with User Defined Function
Count and Sum cells based on specific fill color with Kutools Functions
Count and Sum cells based on specific fill color (or conditional formatting color) with
Kutools for Excel 

 Count And Sum Colored Cells By Filter And SUBTOTAL

Supposing we have a fruit sales table as below screenshot shown, and we will count or sum
the colored cells in the Amount column. In this situation, we can filtered the Amount column by
color, and then count or sum filtered colored cells by the SUBTOTAL function easily in Excel.

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


1. Select blank cells to enter the SUBTOTAL function.
A. To count all cells with the same background color, please enter the formula
=SUBTOTAL(102, E2:E20);
B. To sum all cells with the same background color, please enter the formula
=SUBTOTAL(109, E2:E20);

Note: In both formulas, E2:E20 is the Amount column containing the colored cells, and you can
change them as you need.

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


2. Select the header of the table, and click Data > Filter. See screenshot:

3. Click the Filter icon in the header cell of the Amount column, and click Filter by Color and
the specified color you will count by successively. See screenshot:

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


After filtering, both SUBTOTAL formulas counting and summing all filtered color cells in the
Amount column automatically. See screenshot:

Note: This method requires the colored cells you will count or sum are in the same column.

One Click To Count, Sum, And Average Colored Cells In Excel

With the excellent Count by Color (/product/kutools-for-excel/excel-calculation-based-


on-cell-color.html) feature of Kutools for Excel, you can quickly count, sum, and average
cells by specified fill color or font color with only one click in Excel. Besides, this feature will
also find out the max and min values of cells by the fill color or font color. Full Feature Free
Trial 30-day! (/download/kutools-for-excel.html)

Kutools for Excel (/product/kutools-for-excel.html) - Includes more than 300 handy tools for
Excel. Full feature free trial 30-day, no credit card required! Get It Now (/download/kutools-
Kutools for Excel Solves Most of Your Problems, and Increases
for-excel.html)
Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


 Count Or Sum Colored Cells By GET.CELL Function

In this method, we will create a named range with the GET.CELL function, get the color code of
cells, and then count or sum by the color code easily in Excel. Please do as follows:

1. Click Formulas > Define Name. See screenshot:

2. In the New Name dialog, please do as below screenshot shown:


(1) Type a name in the Name box;
(2) Enter the formula =GET.CELL(38,Sheet4!$E2) in the Refers to box (note: in the formula,
38 means return the cell code, and Sheet4!$E2 is the first cell in the Amount column except the
column header which you need to change based on your table data.)
(3) Click the OK button.

3. Now add a new Color column right to the original table. Next type the formula =NumColor ,
and the drag the AutoFill handle to apply the formula to other cells in the Color column. See
screenshot:

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


Note: In the formula, NumColor is the named range we specified in the first 2 steps. You need
to change it to the specified name you set.

Now the color code of each cell in the Amount column returns in the Color Column. See
screenshot:

4. Copy and list the fill color in a blank range in the active worksheet, and type formulas next to
it as below screenshot shown:
A. To count cells by color, please enter the formula =COUNTIF($F$2:$F$20,NumColor);
B. To sum cells by color, please enter the formula

Kutools for Excel Solves Most of Your Problems, and Increases


=SUMIF($F$2:$F$20,NumColor,$E$2:$E$20).

Your Productivity By 80%. Full Features 30-day Free Trial.


i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


Note: In both formulas, $F$2:$F$20 is the Color column, NumColor is the specified named
range, $E$2:$E$20 is the Amount Column, and you can change them as you need.

Now you will see the cells in the Amount column are counted and sum by their fill colors.

 Count And Sum Cells Based On Specific Fill Color With User Defined Function

Kutools SupposingfortheExcel coloredSolvescells scatter Most of asYour


in a range below Problems,
screenshot shown, and both Increases
above
Yourmethods Productivity
cannot count or sum Bythe80%.
coloredFull Features
cells. Here, this method30-day Free
will introduce Trial.
a VBA to solve
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

the problem. Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications
window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA: Count and sum cells based on background color:

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


1 Function ColorFunction(rColor As Range, rRange As Range, Optional SU
2 Dim rCell As Range
3 Dim lCol As Long
4 Dim vResult
5 lCol = rColor.Interior.ColorIndex
6 If SUM = True Then
7 For Each rCell In rRange
8 If rCell.Interior.ColorIndex = lCol Then
9 vResult = WorksheetFunction.SUM(rCell, vResult)
10 End If
11 Next rCell
12 Else
13 For Each rCell In rRange
14 If rCell.Interior.ColorIndex = lCol Then
15 vResult = 1 + vResult
16 End If
17 Next rCell
18 End If
19 ColorFunction = vResult
20 End Function

3. Then save the code, and apply the following formula:


A. Count the colored cells: =colorfunction(A,B:C,FALSE)
B. Sum the colored cells: =colorfunction(A,B:C,TRUE)

Note: In above formulas, A is the cell with the particular background color you want to calculate
the count and sum, and B:C is the cell range where you want to calculate the count and sum.

4. Take the following screenshot for example, enter the


formula=colorfunction(A1,A1:D11,FALSE) to count the yellow cells. And use the formula
=colorfunction(A1,A1:D11,TRUE) to sum the yellow cells. See screenshot:

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


Kutools for Excel Solves Most of Your Problems, and Increases
Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


5. If you want to count and sum other colored cells, please repeat the step 4. Then you will get
the following results:

 Count And Sum Cells Based On Specific Fill Color With Kutools Functions

Kutools for Excel also supports some useful functions to help Excel users to make special
calculations, says count by cell background color, sum by font color, etc.

Kutools for Excel (/product/kutools-for-excel.html) - Includes more than 300 handy tools
for Excel. Full feature free trial 30-day, no credit card required! Free Trial Now!
(/download/kutools-for-excel.html)

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


1. Select the blank cell you place the counting results, and click Kutools > Kutools Functions
> Statistical & Math > COUNTBYCELLCOLOR. See screenshot:

2. In the Function Arguments dialog, please specify the range you will count colored cells within
in the Reference box, choose the cell that is filled by the specified background color in the
Color_index_nr box, and click the OK button. See screenshot:

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


Notes:
(1) You can also type the specified Kutools Function
=COUNTBYCELLCOLOR($A$1:$E$20,G2) in the blank cell or formula bar directly to get the
counting results;
(2) Click Kutools > Kutools Functions > Statistical & Math > SUMBYCELLCOLOR or type
=SUMBYCELLCOLOR($A$1:$E$20,G2) in the blank cell directly to sum cells based on the
specified background color.

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


Apply the COUNTBYCELLCOLOR and SUMBYCELLCOLOR functions for each background
color separately, and you will get the results as below screenshot shown:

Kutools Functions contain a number of built-in functions to help Excel users calculate easily,
including Count / Sum / Average Visible cells (/product/kutools-for-excel/excel-sum-count-
average-visible-cells-only.html), Count / Sum by cell color (/product/kutools-for-excel/excel-
count-cell-color-function.html), Count / Sum by font color (/product/kutools-for-excel/excel-
count-cell-color-function.html), Count characters (/product/kutools-for-excel/excel-count-the-
number-of-times-a-character-appears.html), Count by font bold (/product/kutools-for-
excel/excel-count-only-bold-cells.html), etc. Have a Free Trial! (/download/kutools-for-
Kutools for Excel Solves Most of Your Problems, and Increases
excel.html)
Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


 Count And Sum Cells Based On Specific Fill Color With Kutools For Excel

With the above User Defined Function, you need to enter the formula one by one, if there are
lots of different colors, this method will be tedious and time-consuming. But if you have Kutools
for Excel’s Count by Color utility, you can quickly generate a report of the colored cells. You
not only can count and sum the colored cells, but also can get the average, max and min
values of the colored range.

Kutools for Excel (/product/kutools-for-excel.html) - Includes more than 300 handy tools
for Excel. Full feature free trial 30-day, no credit card required! Free Trial Now!
(/download/kutools-for-excel.html)

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


1. Select the range that you want to use, and click Kutools Plus > Count by Color, see
screenshot:

2. And in the Count by Color dialog box, please do as below screenshot shown:
(1) Select Standard formatting from the Color method drop down list;
(2) Select Background from the Count type drop down list.
(3) Click the Generate report button.

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


Note: To count and sum colored cells by specific conditional formatting color, please select
Conditional formatting from the Color method drop down list in above dialog, or select
Standard and Conditional formatting from the drop down list to count all cells filled by the
specified color.

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


Now you will get a new workbook with the statistics. See screenshot:

The Count by Color (/product/kutools-for-excel/excel-calculation-based-on-cell-color.html)


feature calculates (Count, Sum, Average, Max, etc.) cells by background color or font color.
Have a Free Trial! (/download/kutools-for-excel.html)

Related Article:

How to count / sum cells based on the font colors in Excel? (/documents/excel/1418-excel-
count-sum-by-font-color.html)

 Demo: Count And Sum Cells Based On Background, Conditional Formatting


Color:

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


How to count and sum cells based on background color i…
·
ExtendOffice - Professional Office Add-ins Follow Share

 Kutools for Excel includes more than 300 handy tools for Excel, free to try without
limitation in 30 days. Download and Free Trial Now (/download/kutools-for-excel.html)!

The Best Office Productivity Tools

Kutools For Excel Solves Most Of Your Problems, And Increases Your
Productivity By 80%
Reuse: Quickly insert complex formulas, charts and anything that you have used before;
Encrypt Cells with password; Create Mailing List and send emails...
Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read
and edit large numbers of cells); Paste to Filtered Range...
Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate
Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and
Fuzzy Find in Many Workbooks; Random Select...
Exact Copy Multiple Cells without changing formula reference; Auto Create References to
Multiple Sheets; Insert Bullets, Check Boxes and more...
Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging
Subtotals; Convert Between Cells Content and Comments...
Super Filter (save and apply filter schemes to other sheets); Advanced Sort by
month/week/day, frequency and more; Special Filter by bold, italic...

Kutools Combine forWorkbooks


Excel Solves MostMerge
and WorkSheets; of Your Problems,
Tables based andSplit
on key columns; Increases
Data into
Your Multiple Productivity
Sheets; Batch Convert By 80%. FullPDF...
xls, xlsx and Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all
languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
60-day money back guarantee.

(/download/kutools-for-excel.html)

Read More... (/product/kutools-for-excel.html) Free Download...


(/download/kutools-for-excel.html) Purchase... (/order/kutools-for-
excel.html)

Office Tab Brings Tabbed Interface To Office, And Make Your Work Much Easier
Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio
and Project.
Open and create multiple documents in new tabs of the same window, rather than in new
windows.
Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!

(/download/office-tab.html)

Read More... (/product/office-tab.html) Free Download...


(/download/office-tab.html) Purchase... (/order/office-tab.html)

230 Comments Login

Sort by Newest b
Say something here...

Dusty · 4 months ago

Is there a way to count different color backgrounds from conditional formatting? The current code as of
7/14/2020 counts them all as default yellow or not at all.
Reply

kellytte · 3 months ago

Hi Dusty,
You can try the Count by Color feature of Kutools for Excel. This feature will help you quickly calculate
(count, sum, average, etc.) cells by cell background color or font color, no matter they are formatted by
conditional formatting or solidly format.

Kutools for Excel Solves Most of Your Problems, and Increases


1155-20200806.png

Your Productivity By 80%. Full Features 30-day Free Trial.


i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
Reply
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /
Dennis · 5 months ago

Did anyone find a solution to auto-refresh? I have to manually refresh for it to update. Otherwise, it works great!
Reply

kellytte · 4 months ago

Hi Dennis,
By default, formulas are calculated in Excel until you are turning off the Automatic Formula Calculation.
You can enable it by clicking Formulas > Calculation Options > Automatic.
Reply

Natasha · 7 months ago

Anyone have tips on a max by color VBA?


Reply

kellytte · 6 months ago

Hi Natasha,
VBA is good but hard to apply. But below methods may solve your work easily too.
Method 1: Use Find & Replace feature to select and statistic the color cells
(1) Press Ctrl + H keys to open the Find and Replace dialog, and then enable the Find tab.
(2) In the dialog, click Options to show advanced find options.
(3) Then click Format > Choose Format From Cell, and select one of the specified color cells.
(4) Click Find All. Now all cells with the same fill color are found out and listed at the bottom of the dialog.
(5) Select one of found cells, and press Ctrl + A to select all found cells, so that these cells are selected in
the worksheet.
(6) Now you can get the count, average, sum, min, max, etc. of these cells in the task bar.
Note: If a certain statistic result cannot be found one the taskbar, you can right click the task bar, and then
tick the specified item to show it.

Method 2: Kutools for Excel


Kutools for Excel supports 30-day free trial. Therefore, you can download it and try its Count by color
feature to solve your problem with several clicks only.
Reply

Paul · 11 months ago

awesome fix! count by color over an entire sheet was just what i was looking for and your VBA code was tighter
than others that i have looked at. Works like a charm. Thank you, and again, well done.
Reply

Mori · 1 years ago

I copied and paste but calculation result is "0" why?? I am using Office 2016.
Reply

· 10 months ago
Krits

Kutools forsame
I try the Excel
you thisSolves Most of Your isProblems,
command =COUNTBYCELLCOLOR and
counting only fill color but Increases
is not count by

Your Productivity By 80%. Full Features 30-day Free Trial.


condition formating. Please help to improve code thx.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
Reply
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /
havdaddy · 1 years ago

I've copied and pasted as stated and have used this formula for over a year but recently saved the workbook to a
new name and now the function doesn't work! I can't figure out what the deal is and I'm losing hair and sleep
over it! Loading the original workbook, the formula works like a charm but going back to the new one, it doesn't!
I've loaded VBA and tried re-creating the function but it doesn't work. Using Office 2019 - any help appreciated.
Reply

Jku · 1 years ago

#NAME clearly indicates some keyword is not used in 2019, say, Interior.ColorIndex. Try to figure out
changing the code from minimum lines to the full by adding one by one or search for the keywords in
Excel/VBA in 2019
Reply

havdaddy · 1 years ago

I should probably have also noted that I get a #NAME? error in the cell in which I try to use the function.
Reply

Karolin · 1 years ago

works fine, except it does not update the value in the totals when i change a cell to a diffrent colour. i have to
click in the totals cell again to trigger a recount. Any Ideas how to fix this?
Reply

[email protected] · 1 years ago

Same here, i tried Ctrl+Alt+F9 or Ctrl+Shift+Alt+F9 to recalculate all formula and it works
Reply

Aaron · 2 years ago

This doesn't work at all. It's total BS.


Reply

Schmingy · 2 years ago

I was experiencing issues when attempting to use this function as-is to count/sum the lighter (pastel?) colors, at
least in Excel 2016. Some debugging led me to realize that the range of "ColorIndex" values is quite limited, and
the function above fails to distinguish between light yellow and light orange, reading both as ColorIndex = 19.

Using the "Color" attribute, instead (as in "lCol = rColor.Interior.Color" and the two instances of "If
rCell.Interior.Color = lCol Then", per the sample code above), resolved the issue.
Reply

Hredoy · 2 years ago

i want to colour in excel by using if function.

Kutools
Reply
for Excel Solves Most of Your Problems, and Increases
Your· Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
Keerthi 2 years ago
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /
Fix your formula, its not "=colorfunction(A,B:C,FALSE)", but "=colorfunction(A;B:C;FALSE)" its a semi-colon, not
a comma.
Reply

Slegnor · 2 years ago

I get an error when using ; but using, calculates fine?


Reply

Don Sison · 2 years ago

This is useful for counting cells with a specific colour. How do you count all cells with any colour?
Reply

Ashwin · 2 years ago

Its work for me but does not get Auto refreshed - evey time i have to come back to cell and press enter. Any
reason ?
Reply

Bobo · 2 years ago

I have a few merged cells in the range, and the formula calculates the count of each cell within merged cell. I
need count of each merged cell as 1. Waiting for some help.
Reply

Paul · 2 years ago

I had the #NAME Error but I realised that it was because I was spelling COLOR as Colour (UK English Spelling).
It worked after I change the spelling.
Reply

Oana · 2 years ago

I tried to use this formula in a pivot table (and in a normal excel table) where I've applied conditional formatting to
color the cells and it's not working. Do you know why and how can I fix this?
Thanks!
Reply

Will · 2 years ago

I copied and pasted this code into the module screen but when I went back to the spreadsheet, the
ColorFunction only returned the #NAME? error. What am I doing wrong? I have Microsoft Excel for Mac version
15.41.
Reply

Arjun · 2 years ago

I used the Code and it was working fine till now. Suddenly it has stopped working. This is a very useful
Kutools for Excel Solves Most of Your Problems, and Increases
tool for me. Kindly help.

Your Reply
Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

amohuanna Yes·please! 2 years ago (https://www.extendoffice.com/download/kutools-for-excel.html) /


Did you check the range value and cell that contains the desired color?
Reply

kasim · 2 years ago

Please this VBA with the name of MY FUNCTION save as add in format(type). Then you can solve that
problem.
Reply

[email protected] · 2 years ago

I'm having this same problem, and unfortunately this answer makes absolutely zero sense in the
English language. If anyone is able to suggest a translation, I'd be very interested in hearing it.
Thanks.
Reply

Erin · 2 years ago

The module & function can't have the same name. Change your module name to
Color_Function instead of ColorFunction.
Reply

Jelena · 2 years ago

Hi

after applying range we need it jums back to VBA and says Ambiguous name detected: ColourFunction

can you please help?


Reply

[email protected] · 3 years ago

this doesn't work if you change the colors in the cells: so if you change yellow to red or yellow to blank, it doesn't
change the count. if you add/create new colored cells then yes it updates the count, but if you change the color
of a cell that has already been counted, then the count will not update.
Reply

Penny · 2 years ago

if you go back in the cell text with the formula for summing or counting and hit enter, it will recalculate.
Just have to remember to do that when changing colors on the range cells.
Reply

Tim · 2 years ago

Is there a way to auto-calculate? going into each cell and hitting enter each time colors change is
extremely tedious.

Kutools for Reply


Excel Solves Most of Your Problems, and Increases
Your Productivity By 80%. Full Features 30-day Free Trial.
Casey · 3 years ago
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

This has been Yes please!


so useful! Thanks very (https://www.extendoffice.com/download/kutools-for-excel.html)
much for your help /
Reply

Carolyn · 3 years ago

The =colorfunction WAS working great for me ... got everything as I wanted it to work and then copied the sheet
repeatedly ... then around the 10th copied sheet the formula stopped working ... what did I do wrong? How do I
fix it?
Reply

luisa · 3 years ago

hey, we used the colorfunction and it works fine, however as soon as we close the sheet and open it again the
next day, we have to copy+paste+save it all over again, is there any way to save so it will always be there? we
save the sheet in a folder that's shared within many computers. Thanks!
Reply

Tim · 3 years ago

Luisa,
When you open VBA, you have VBAProject (sheet1) its the place for makros for THIS SHEET. But you
also have VBA Projects (PERSONAL.XLSB). Add module in PERSONAL and paste this makro there.
This way you will have function avialable in every file on your computer.
Im not sure but probably you dont have this PRESONAL.XLSB automaticly, you need to create it.
Probably not the the fastest way but : click record macro, window will apear where you put name
(whatever), shortcut (whatever) and place to store makro (chose personal macros sheet). Click ok, record
any makro (puting 1 in cell A1), stop recording. Now you should have PERSONAL.XLSB in the list.
Hope it works and helps :)
Reply

Justin · 3 years ago

This works great unless you are trying to count colors from conditional formatting. Has anybody figured out how
to solve that one?
Reply

Alex · 2 years ago

Have you found a solution to this? I am trying to do the same thing but like you said, it does not work with
conditional formatting.
Reply

[email protected] · 3 years ago

This doesn't differentiate between similar colours, so I changed it so it calls the HEX value of the colour instead:

Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean) As Variant


Dim rCell As Range
Dim lCol As Variant
Dim vResult As Variant

Kutools for Excel Solves Most of Your Problems, and Increases


lCol = rColor.Interior.Color
If SUM = True Then
Your Productivity By 80%. Full Features 30-day Free Trial.
For Each rCell In rRange
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
If rCell.Interior.Color = lCol Then
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else For Each rCell In rRange
If rCell.Interior.Color = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function

Just remember when applying the formula that A cell of the colour you are looking for and B:C is the range to
look in. Also, remember that excel can sometimes not auto-update any change to the cell so you might have to
manually do it (or write a function ;-)
Reply

manali · 3 years ago

I implemented case 1 and it worked successfully. But whenever I change the color the count does not change
automatically. I need to click on Count and press enter. Can't the count be changed automatically?
Reply

Wendy · 3 years ago

Did you find a solution to this b/c I'm having the same problem.
Reply

LiamKennedy1985 · 3 years ago

Any news on this? I am having the same issue. Otherwise perfect :-)
Reply

Ryan · 3 years ago

Code works perfectly but also ran into the same issue. Solved it by writing a quick macros
that 'refreshes' the function(s) in the cells assigned so you have an accurate count as soon
as you run the macros. Hope this helps!
Reply

Drew · 3 years ago

Could you share the code you used to "refresh" the macros? I'd greatly appreciate
it.
Reply

Hellen Hornby · 3 years ago

Hi I tried the above in Excel and keep getting a 'ambiguous name detected' error message related to the
colorfunction. Any thoughts?
Kutools
Reply for Excel Solves Most of Your Problems, and Increases
Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
a · 3 years ago
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /
the function does not differentiate between colours. it just counts any cell this is coloured.
Reply

[email protected] · 3 years ago

See my new reply, I've updated it so it will now differentiate between similar colours.
Reply

Andrea · 3 years ago

Hi

Fantastic tool and really easy to use so thank you!

Is there any update on using this with conditional formatting? I think there is a fix above but I didn't understand
how it worked. Simple instructions for a novice would be much appreciated!

Thanks :)
Reply

saurabh · 3 years ago

everything is good but what if i want to add cells across multiple worksheet
Reply

Hien · 3 years ago

$2,322.29 2322.29
$100.00 128.66
$76.13 76.13
$450.02 450.02
$28.66 128.66
$544.31 488.77

00
$278.66
$636.76 636.76
Please help the numbers on the left are the correct number but when i dragged down the formula i get the
numbers on the right. As you can see some of the numbers are correct but others come out wrong. Please help
me, i dont understand why this is not working. Thanks.
Reply

Hien · 3 years ago

Please help, why do some of my numbers come out correct and some do not? Maybe two out of the 6 will be
inccorect because its adding a different number from a different color.
Reply

· 3 years ago
mc
Kutools for Excel Solves Most of Your Problems, and Increases
Change everything that says ".colorindex" to ".color"
Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
.ColorIndex only supports 256 Colours. And will round similar colours together essentuially.
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /
Reply

RB · 3 years ago

Very Helpful.

Thanks a Lot.

BR,
RB.
Reply

Vamshi · 3 years ago

The above function is only working for the data in a single sheet
I want to capture the data from multiple workbooks.

Please help .
Reply

Vamshi · 3 years ago

Hello,

The above function works only if the all the coloured cells are in single sheet .
I am unable to perform the colorfunction sum if the coloured cells are in different sheets.
Any help around this.

EX;- Trying to consolidate the sum of coloured cells in a Master sheet it says #VALUE
Reply

Sarah Chen · 3 years ago

Thanks for this. It's truely helpful to me!!!


Reply

Ramdzan · 3 years ago

its a good function however it can't be save for the entire workbook, whenever to go to a new worksheet and I
copy and paste the previous worksheet with the function it doesn't work and then must do it all over again, please
advise if there anyway I can save the function for free ofcoz :0
Reply

AHMER IRFAN · 3 years ago

Jazak ALLAH it was very helpful


Reply

Jacqui · 3 years ago


Kutools for Excel Solves Most of Your Problems, and Increases
Your Productivity By 80%. Full Features 30-day Free Trial.
Brilliant! I've been searching for a way to do this. Works perfectly and will save me so much time!!
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)
Reply
Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /
Rod · 3 years ago

Lack me words to express my gratitude for your code. You've saved a lot of time, wish a could buy you a beer.

All the best, mate.


Reply

Phillip · 4 years ago

Hi,

Is there any way to change the code so that instead of calculating a SUM when set to TRUE, it will count the
number of cells with numbers or text in?? Ideally I would like if it could count a number over 10,000, but just the
COUNT function would be great. I have tried simply changing SUM in the code to COUNT, but it doesn't work.

Any help would be great


Reply

Himmat · 4 years ago

Good day,

I have tried the coding provided. However I am using different color themes, which does not provide me with the
answers I am seeking as the coding sums colors of a similar background and I need to obtain the sun for
different colors. please assist
Reply

Ken · 4 years ago

It's not working for me. I'm running Excel 2013 but I keep getting the Ambiguous name detected: colorfunction.
Is there a way to fix this?
Reply

Dazzy · 4 years ago

Fantastic! Worked very well.


Reply

Akshatha · 4 years ago

Hi,

Works Great. Needed a small tweak though. I have some colored empty cells which are also getting counted
right now. How can i ignore those cells?

Thanks
Reply

Sylvia · 4 years ago


Kutools for Excel Solves Most of Your Problems, and Increases
Your code works really well. Thanks. Can you now please help to alter the function of colorfunction so
Your merged
horizontally Productivity
cell is counted as Byone?80%. Full
I am using Features
the following function:30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html)


Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
/
Dim rCell As Range
Dim lCol As Long
Dim vResult
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function

Thanks!
Reply

GV · 4 years ago

Works Great !!!


Thanks for posting!!
Reply

Kailas · 4 years ago

Thanks! very useful function :)


Reply

Ranj · 4 years ago

I have enabled macros to count cell colors. How do add another criteria for text? Lets say I have checked a
range and recieved the count for cells that are green. How do I also check how many of those had "D" as text?

thanks!
Reply

GK · 4 years ago

Worked like a charm when other codes would not! THANK YOU!
Reply

Saifi· 4 years ago


Kutools forhelpful
Thankyou. very Excel Solves Most of Your Problems, and Increases
information

Your Productivity By 80%. Full Features 30-day Free Trial.


Reply
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /


1 (https://www.extendoffice.com/documents/excel/1155-excel-count-sum-cells-by-color.html?page_comment=1)

2 (https://www.extendoffice.com/documents/excel/1155-excel-count-sum-cells-by-color.html?page_comment=2)

3 (https://www.extendoffice.com/documents/excel/1155-excel-count-sum-cells-by-color.html?page_comment=3)

4 (https://www.extendoffice.com/documents/excel/1155-excel-count-sum-cells-by-color.html?page_comment=4)

 Home (/)  Knowledge (/documents.html)  Support (/support.html)

 Forum (/forum.html)  Privacy Policy (/privacy-policy.html)

 About Us (/support/about-us.html)
Follow us

(http://www.facebook.com/extendoffice)

(http://twitter.com/intent/follow?
source=followbutton&variant=1.0&screen_name=extendoffice)
Copyright © 2009 - 2020 ExtendOffice.com | All Rights Reserved.  Sitemap
(/support/sitemap.html)
Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation
in the United States and/or other countries.

(https://sectigo.com/trust-seal)

Kutools for Excel Solves Most of Your Problems, and Increases


Your Productivity By 80%. Full Features 30-day Free Trial.
i (https://www.addthis.com/website-tools/overview?utm_source=AddThis%20Tools&utm_medium=image&utm_campaign=Marketing%20tool%20logo)

Yes please! (https://www.extendoffice.com/download/kutools-for-excel.html) /

You might also like