Note: The other languages of the website are Google-translated. Back to English
登陆  \/ 
x
or
x
点此注册  \/ 
x

or

如何在Excel中根据背景色对单元格进行计数和求和?

假设您有一系列具有不同背景颜色的单元格,例如红色,绿色,蓝色等,但是现在您需要计算该范围内有特定背景颜色的单元格的数量,并对具有相同特定颜色的彩色单元格求和。 在Excel中,没有直接公式可以计算颜色单元的总数和计数,这里我将向您介绍一些解决此问题的方法。


通过过滤器和小计对有色单元进行计数和求和

假设我们有一个水果销售表,如下图所示,我们将对“金额”列中的彩色单元格进行计数或求和。 在这种情况下,我们可以按颜色过滤“金额”列,然后在Excel中通过SUBTOTAL函数轻松地对已过滤的彩色单元格进行计数或求和。

1。 选择空白单元格以输入SUBTOTAL功能。

  1. 要计算具有相同背景色的所有单元格,请输入公式 =小计(102,E2:E20);
  2. 要对所有具有相同背景色的单元格求和,请输入公式 =小计(109,E2:E20);


备注:在两个公式中,E2:E20是包含彩色单元格的Amount列,您可以根据需要进行更改。

2。 选择表的标题,然后单击 数据 > 滤波器。 看截图:

3。 点击过滤器图标  在“金额”列的标题单元格中,然后单击 通过彩色滤光片 以及您将依次计算的指定颜色。 看截图:

过滤后,两个SUBTOTAL公式都会自动对“金额”列中所有过滤的颜色单元进行计数和求和。 看截图:

备注:此方法需要将要计数或求和的彩色单元格放在同一列中。

一键计算,汇总和平均Excel中的彩色单元格

随着优秀 按颜色计数 的特点 Kutools for Excel,您只需在Excel中一键即可按指定的填充颜色或字体颜色对单元格进行快速计数,求和和平均。 此外,此功能还将通过填充颜色或字体颜色找出单元格的最大值和最小值。 全功能30天免费试用!
按颜色2的广告计数

Kutools for Excel -包括300多个用于Excel的便捷工具。 全功能30天免费试用,无需信用卡! 立即行动吧!

通过GET.CELL函数对有色单元格进行计数或求和

在此方法中,我们将使用GET.CELL函数创建命名范围,获取单元格的颜色代码,然后在Excel中轻松按颜色代码进行计数或求和。 请执行以下操作:

1。 点击 公式 > 定义名称。 看截图:

2。 在“新名称”对话框中,请执行以下显示的屏幕截图:
(1)在“名称”框中键入名称;
(2)输入公式 = GET.CELL(38,Sheet4!$ E2) 在“引用”框中(注意: 在公式, 38 表示返回单元格代码,并且 Sheet4!$ E2 是“金额”列中的第一个单元格,但您需要根据表格数据更改列标题。)
(3)点击 OK 按钮。

3。 现在,在原始表的右侧添加一个新的“颜色”列。 接下来输入公式 = NumColor ,然后拖动自动填充手柄将公式应用于“颜色”列中的其他单元格。 看截图:
备注: 在公式, 数字颜色 是我们在前两个步骤中指定的命名范围。 您需要将其更改为您设置的指定名称。

现在,“金额”列中每个单元格的颜色代码将在“颜色”列中返回。 看截图:

4。 复制并列出活动工作表中空白区域中的填充颜色,并在其旁边键入公式,如下所示:
A.要按颜色对单元格进行计数,请输入公式 = COUNTIF($ F $ 2:$ F $ 20,NumColor);
B.要按颜色对单元格求和,请输入公式 = SUMIF($ F $ 2:$ F $ 20,NumColor,$ E $ 2:$ E $ 20).

备注:在两个公式中 $ F $ 2:$ F $ 20 是“颜色”列, 数字颜色 是指定的命名范围, $ E $ 2:$ E $ 20 是“金额”列,您可以根据需要进行更改。

现在,您将看到“数量”列中的单元格已被计数并通过其填充颜色求和。


使用用户定义的功能根据特定的填充颜色对单元格进行计数和求和

假设有色单元散布在如下所示的屏幕快照范围内,则上述两种方法都无法对有色单元进行计数或求和。 在此,此方法将介绍VBA以解决该问题。

1。 按住 ALT + F11 键,然后打开 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块,然后将以下代码粘贴到“模块窗口”中。

VBA:根据背景色对单元格进行计数和求和:

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

3。 然后保存代码,并应用以下公式:
A.计算有色细胞: = colorfunction(A,B:C,FALSE)
B.对有色单元格求和: = colorfunction(A,B:C,TRUE)

注意:在上述公式中, A 是您要计算计数和总和的具有特定背景颜色的单元格,并且 公元前 是您要计算计数和总和的单元格范围。

4。 以以下屏幕截图为例,输入公式= colorfunction(A1,A1:D11,FALSE) 计算黄色细胞。 并使用公式 = colorfunction(A1,A1:D11,TRUE) 总结黄色细胞。 看截图:

5。 如果要对其他有色单元格进行计数和求和,请重复步骤4。然后您将获得以下结果:


使用Kutools函数根据特定的填充颜色对单元格进行计数和求和

Kutools for Excel还支持一些有用的功能来帮助Excel用户进行特殊计算,例如按单元格背景颜色计数,按字体颜色计数之和等等。

Kutools for Excel -包括300多个用于Excel的便捷工具。 全功能30天免费试用,无需信用卡! 立即免费试用!

1。 选择放置计数结果的空白单元格,然后单击 库工具 > Kutools函数 > 统计与数学 > 单色。 看截图:

2。 在“函数参数”对话框中,请指定要计算的彩色单元格范围。 参考 框中,选择由指定背景颜色填充的单元格 color_index_nr 框,然后单击 OK 按钮。 看截图:

备注:
(1)您也可以输入指定的Kutools函数 = COUNTBYCELLCOLOR($ A $ 1:$ E $ 20,G2)  直接在空白单元格或公式栏中获取计数结果;
(2)点击 库工具 > Kutools函数 > 统计与数学 > 超级手机颜色 或输入 = SUMBYCELLCOLOR($ A $ 1:$ E $ 20,G2) 直接在空白单元格中根据指定的背景色对单元格求和。
应用 单色 以及 超级手机颜色 分别为每种背景色提供功能,您将获得如下屏幕截图所示的结果:

Kutools函数 包含许多内置函数来帮助Excel用户轻松计算,包括 计数/总和/平均可见单元格, 按单元格颜色计数/求和, 按字体颜色计数/求和, 计数字符, 按字体粗体计数等等。 免费试用!


使用Kutools for Excel根据特定的填充颜色对单元格进行计数和求和

使用上面的用户定义函数,您需要一个一个地输入公式,如果有很多不同的颜色,此方法将很繁琐且耗时。 但是如果你有 Kutools for Excel按颜色计数 实用程序,您可以快速生成彩色单元格的报告。 您不仅可以对有色单元格进行计数和求和,还可以获取有色范围的平均值,最大值和最小值。

Kutools for Excel -包括300多个用于Excel的便捷工具。 全功能30天免费试用,无需信用卡! 立即免费试用!

1。 选择您要使用的范围,然后单击 Kutools Plus > 按颜色计数,请参见屏幕截图:

2。 和在 按颜色计数 对话框,请按如下所示进行截图:
(1)选择 标准格式 来自 上色方式 下拉列表;
(2)选择 背景 来自 计数类型 下拉列表。
(3)单击生成报告按钮。

备注:要按特定的条件格式颜色对有色单元格进行计数和求和,请选择 条件格式 来自 上色方式 对话框上方的下拉列表,或选择 标准和条件格式 从下拉列表中计算指定颜色填充的所有单元格。

现在,您将获得一个包含统计信息的新工作簿。 看截图:

- 按颜色计数 功能通过背景颜色或字体颜色计算(计数,总和,平均值,最大值等)单元格。 免费试用!


相关文章:


演示:根据背景和条件格式颜色对单元格进行计数和求和:


Kutools for Excel 包括适用于Excel的300多种便捷工具,可以在30天之内免费试用。 立即下载并免费试用!

最佳办公效率工具

Kutools for Excel解决了您的大多数问题,并使您的生产率提高了80%

  • 重用: 快速插入 复杂的公式,图表 以及您以前使用过的任何东西; 加密单元 带密码 创建邮件列表 并发送电子邮件...
  • 超级公式栏 (轻松编辑多行文本和公式); 阅读版式 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不会丢失数据; 拆分单元格内容; 合并重复的行/列...防止细胞重复; 比较范围...
  • 选择重复或唯一 行; 选择空白行 (所有单元格都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择...
  • 确切的副本 多个单元格,无需更改公式参考; 自动创建参考 到多张纸; 插入项目符号,复选框等...
  • 提取文字,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级滤镜 (将过滤方案保存并应用于其他工作表); 高级排序 按月/周/日,频率及更多; 特殊过滤器 用粗体,斜体...
  • 结合工作簿和工作表; 根据关键列合并表; 将数据分割成多个工作表; 批量转换xls,xlsx和PDF...
  • 超过300种强大功能。 支持Office / Excel 2007-2019和365。支持所有语言。 在您的企业或组织中轻松部署。 完整功能30天免费试用。 60天退款保证。
kte选项卡201905

Office选项卡为Office带来了选项卡式界面,使您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
officetab底部
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Dusty · 1 years 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.
    • To post as a guest, your comment is unpublished.
      kellytte · 11 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.
  • To post as a guest, your comment is unpublished.
    Dennis · 1 years ago
    Did anyone find a solution to auto-refresh? I have to manually refresh for it to update. Otherwise, it works great!
    • To post as a guest, your comment is unpublished.
      kellytte · 1 years 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.
  • To post as a guest, your comment is unpublished.
    Natasha · 1 years ago
    Anyone have tips on a max by color VBA?
    • To post as a guest, your comment is unpublished.
      kellytte · 1 years 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.
  • To post as a guest, your comment is unpublished.
    Paul · 1 years 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.
  • To post as a guest, your comment is unpublished.
    Mori · 2 years ago
    I copied and paste but calculation result is "0" why?? I am using Office 2016.
    • To post as a guest, your comment is unpublished.
      Krits · 1 years ago
      I try the same you this command =COUNTBYCELLCOLOR is counting only fill color but is not count by condition formating. Please help to improve code thx.
  • To post as a guest, your comment is unpublished.
    havdaddy · 2 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.
    • To post as a guest, your comment is unpublished.
      Jku · 2 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
    • To post as a guest, your comment is unpublished.
      havdaddy · 2 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.
  • To post as a guest, your comment is unpublished.
    Karolin · 2 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?
    • To post as a guest, your comment is unpublished.
      amirhamzah2107@gmail.com · 2 years ago
      Same here, i tried Ctrl+Alt+F9 or Ctrl+Shift+Alt+F9 to recalculate all formula and it works
  • To post as a guest, your comment is unpublished.
    Aaron · 2 years ago
    This doesn't work at all. It's total BS.
  • To post as a guest, your comment is unpublished.
    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.
  • To post as a guest, your comment is unpublished.
    Hredoy · 3 years ago
    i want to colour in excel by using if function.
  • To post as a guest, your comment is unpublished.
    Keerthi · 3 years ago
    Fix your formula, its not "=colorfunction(A,B:C,FALSE)", but "=colorfunction(A;B:C;FALSE)" its a semi-colon, not a comma.
    • To post as a guest, your comment is unpublished.
      Slegnor · 3 years ago
      I get an error when using ; but using, calculates fine?
  • To post as a guest, your comment is unpublished.
    Don Sison · 3 years ago
    This is useful for counting cells with a specific colour. How do you count all cells with any colour?
  • To post as a guest, your comment is unpublished.
    Ashwin · 3 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 ?
  • To post as a guest, your comment is unpublished.
    Bobo · 3 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.
  • To post as a guest, your comment is unpublished.
    Paul · 3 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.
  • To post as a guest, your comment is unpublished.
    Oana · 3 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!
  • To post as a guest, your comment is unpublished.
    Will · 3 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.
    • To post as a guest, your comment is unpublished.
      Arjun · 3 years ago
      I used the Code and it was working fine till now. Suddenly it has stopped working. This is a very useful tool for me. Kindly help.
    • To post as a guest, your comment is unpublished.
      amohuanna · 3 years ago
      Did you check the range value and cell that contains the desired color?
    • To post as a guest, your comment is unpublished.
      kasim · 3 years ago
      Please this VBA with the name of MY FUNCTION save as add in format(type). Then you can solve that problem.
      • To post as a guest, your comment is unpublished.
        andrew.carpenter@gmail.com · 3 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.
        • To post as a guest, your comment is unpublished.
          Erin · 3 years ago
          The module & function can't have the same name. Change your module name to Color_Function instead of ColorFunction.
  • To post as a guest, your comment is unpublished.
    Jelena · 3 years ago
    Hi


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

    can you please help?
  • To post as a guest, your comment is unpublished.
    kelli.crook9@gmail.com · 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.
    • To post as a guest, your comment is unpublished.
      Penny · 3 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.
      • To post as a guest, your comment is unpublished.
        Tim · 3 years ago
        Is there a way to auto-calculate? going into each cell and hitting enter each time colors change is extremely tedious.
  • To post as a guest, your comment is unpublished.
    Casey · 3 years ago
    This has been so useful! Thanks very much for your help
  • To post as a guest, your comment is unpublished.
    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?
  • To post as a guest, your comment is unpublished.
    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!
    • To post as a guest, your comment is unpublished.
      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 :)
  • To post as a guest, your comment is unpublished.
    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?
    • To post as a guest, your comment is unpublished.
      Alex · 3 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.
  • To post as a guest, your comment is unpublished.
    cobalt.kobold@gmail.com · 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
    lCol = rColor.Interior.Color
    If SUM = True Then
    For Each rCell In rRange
    If rCell.Interior.Color = lCol Then
    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 ;-)
  • To post as a guest, your comment is unpublished.
    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?
    • To post as a guest, your comment is unpublished.
      Wendy · 3 years ago
      Did you find a solution to this b/c I'm having the same problem.
      • To post as a guest, your comment is unpublished.
        LiamKennedy1985 · 3 years ago
        Any news on this? I am having the same issue. Otherwise perfect :-)
        • To post as a guest, your comment is unpublished.
          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!
          • To post as a guest, your comment is unpublished.
            Drew · 3 years ago
            Could you share the code you used to "refresh" the macros? I'd greatly appreciate it.
  • To post as a guest, your comment is unpublished.
    Hellen Hornby · 4 years ago
    Hi I tried the above in Excel and keep getting a 'ambiguous name detected' error message related to the colorfunction. Any thoughts?
  • To post as a guest, your comment is unpublished.
    a · 4 years ago
    the function does not differentiate between colours. it just counts any cell this is coloured.
    • To post as a guest, your comment is unpublished.
      cobalt.kobold@gmail.com · 3 years ago
      See my new reply, I've updated it so it will now differentiate between similar colours.
  • To post as a guest, your comment is unpublished.
    Andrea · 4 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 :)
  • To post as a guest, your comment is unpublished.
    saurabh · 4 years ago
    everything is good but what if i want to add cells across multiple worksheet
  • To post as a guest, your comment is unpublished.
    Hien · 4 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

    0 0
    $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.
  • To post as a guest, your comment is unpublished.
    Hien · 4 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.
    • To post as a guest, your comment is unpublished.
      mc · 4 years ago
      Change everything that says ".colorindex" to ".color"

      .ColorIndex only supports 256 Colours. And will round similar colours together essentuially.
  • To post as a guest, your comment is unpublished.
    RB · 4 years ago
    Very Helpful.

    Thanks a Lot.

    BR,
    RB.
  • To post as a guest, your comment is unpublished.
    Vamshi · 4 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 .
  • To post as a guest, your comment is unpublished.
    Vamshi · 4 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
  • To post as a guest, your comment is unpublished.
    Sarah Chen · 4 years ago
    Thanks for this. It's truely helpful to me!!!
  • To post as a guest, your comment is unpublished.
    Ramdzan · 4 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
  • To post as a guest, your comment is unpublished.
    AHMER IRFAN · 4 years ago
    Jazak ALLAH it was very helpful
  • To post as a guest, your comment is unpublished.
    Jacqui · 4 years ago
    Brilliant! I've been searching for a way to do this. Works perfectly and will save me so much time!!
  • To post as a guest, your comment is unpublished.
    Rod · 4 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.
  • To post as a guest, your comment is unpublished.
    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
  • To post as a guest, your comment is unpublished.
    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
  • To post as a guest, your comment is unpublished.
    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?
  • To post as a guest, your comment is unpublished.
    Dazzy · 4 years ago
    Fantastic! Worked very well.
  • To post as a guest, your comment is unpublished.
    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
  • To post as a guest, your comment is unpublished.
    Sylvia · 4 years ago
    Your code works really well. Thanks. Can you now please help to alter the function of colorfunction so horizontally merged cell is counted as one? I am using the following function:
    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!
  • To post as a guest, your comment is unpublished.
    GV · 4 years ago
    Works Great !!!
    Thanks for posting!!
  • To post as a guest, your comment is unpublished.
    Kailas · 4 years ago
    Thanks! very useful function :)
  • To post as a guest, your comment is unpublished.
    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!
  • To post as a guest, your comment is unpublished.
    GK · 4 years ago
    Worked like a charm when other codes would not! THANK YOU!
  • To post as a guest, your comment is unpublished.
    Saifi · 4 years ago
    Thankyou. very helpful information