提示:其他語言是Google翻譯的。 你可以訪問 English 版本。
登入
x
or
x
x
註冊
x

or

如何計算和統計基於Excel中的背景顏色的單元格?

假設您有一系列具有不同背景顏色的單元格,例如紅色,綠色,藍色等,但現在您需要計算該範圍內有多少單元格具有特定背景顏色,並將具有相同特定顏色的彩色單元格相加。 在Excel中,沒有直接的公式來計算顏色單元的總和和計數,這裡我將向您介紹一些解決此問題的方法。

通過Filter和SUBTOTAL基於特定填充顏色計算和求和單元格

通過GET.CELL函數根據特定填充顏色計數和求和單元格

使用用戶定義函數根據特定填充顏色計算和求和單元格

使用Kutools函數根據特定填充顏色計算和求和單元格

使用Kutools for Excel基於特定填充顏色(或條件格式顏色)計算和求和單元格

單擊以在Excel中計算,求和和平均彩色單元格

隨著優秀 按顏色計數 的特點 Kutools for Excel,只需在Excel中單擊一下,即可按指定的填充顏色或字體顏色快速計算,求和和平均單元格。 此外,此功能還將通過填充顏色或字體顏色找出單元格的最大值和最小值。 全功能免費試用30天!
廣告按顏色計算2


通過Filter和SUBTOTAL計算和求和單元格

假設我們有一個水果銷售表,如下面的屏幕截圖所示,我們將對Amount列中的彩色單元格進行計數或求和。 在這種情況下,我們可以按顏色過濾Amount列,然後在Excel中通過SUBTOTAL函數對過濾的彩色單元格進行計數或求和。

1。 選擇空白單元格以進入SUBTOTAL功能。

  1. 要計算具有相同背景顏色的所有單元格,請輸入公式 = SUBTOTAL(102,E2:E20);
  2. 要對具有相同背景顏色的所有單元格求和,請輸入公式 = SUBTOTAL(109,E2:E20);


備註:在兩個公式中,E2:E20是包含彩色單元格的Amount列,您可以根據需要更改它們。

2。 選擇表格的標題,然後單擊 數據 > 過濾。 看截圖:

3。 單擊“過濾器”圖標 在Amount列的標題單元格中,單擊 通過彩色濾光片 和您將連續計算的指定顏色。 看截圖:

過濾後,兩個SUBTOTAL公式都會自動計算和計算Amount列中所有已過濾的顏色單元格。 看截圖:

備註:此方法要求您將計算或總和的彩色單元格位於同一列中。


通過GET.CELL函數對彩色單元格進行計數或求和

在這個方法中,我們將使用GET.CELL函數創建一個命名範圍,獲取單元格的顏色代碼,然後在Excel中輕鬆地按顏色代碼計算或求和。 請做如下:

1。 點擊 公式 > 定義名稱。 看截圖:

2。 在New Name對話框中,請按以下屏幕截圖顯示:
(1)在“名稱”框中鍵入名稱;
(2)輸入公式 = GET.CELL(38,Sheet4!$ E2) 在參考框中(注意: 在公式, 38 表示返回單元格代碼,和 Sheet4!$ E2 是Amount列中的第一個單元格,除了您需要根據表數據更改的列標題。)
(3)點擊 OK 按鈕。

3。 現在將新的Color列添加到原始表的右側。 接下來輸入公式 = NUM​​COLOR ,並拖動自動填充處理以將公式應用於“顏色”列中的其他單元格。 看截圖:
備註: 在公式, NUMCOLOR 是我們在第一個2步驟中指定的命名範圍。 您需要將其更改為您設置的指定名稱。

現在,“數量”列中每個單元格的顏色代碼將在“顏色”列中返回。 看截圖:

4。 複製並列出活動工作表中空白範圍內的填充顏色,並在其旁邊鍵入公式,如下面的屏幕截圖所示:
A.要按顏色計算單元格,請輸入公式 = COUNTIF($ F $ 2:$ F $ 20,NUMCOLOR);
B.要按顏色對單元格求和,請輸入公式 = SUMIF($ F $ 2:$ F $ 20,NUMCOLOR,$ E $ 2:$ E $ 20).

備註:在兩個公式中, $ F $ 2:$ F $ 20 是Color列, NUMCOLOR 是指定的命名範圍, $ E $ 2:$ E $ 20 是金額列,您可以根據需要更改它們。

現在,您將看到Amount列中的單元格已計數,並按填充顏色求和。


使用用戶定義函數根據特定填充顏色計算和求和單元格


假設有色單元在如下面的屏幕截圖所示的範圍內散佈,上述兩種方法都不能對彩色單元格進行計數或求和。 這裡,這個方法將引入一個VBA來解決這個問題。

1。 按住 ALT + F11 鍵,然後打開 Microsoft Visual Basic for Applications 窗口。

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 -包括多個用於Excel的300便捷工具。 全功能免費試用30天,無需信用卡! 立即行動吧

1。 選擇放置計數結果的空白單元格,然後單擊 Kutools > Kutools函數 > 統計與數學 > COUNTBYCELLCOLOR。 看截圖:

2。 在“函數參數”對話框中,請指定計算顏色單元格的範圍 參考 框,選擇由指定的背景顏色填充的單元格 Color_index_nr 框中,然後單擊 OK 按鈕。 看截圖:

筆記:
(1)您也可以鍵入指定的Kutools函數 = COUNTBYCELLCOLOR($ A $ 1:$ E $ 20,G2) 在空白單元格或公式欄中直接得到計數結果;
(2)點擊 Kutools > Kutools函數 > 統計與數學 > SUMBYCELLCOLOR 或鍵入 = SUMBYCELLCOLOR($ A $ 1:$ E $ 20,G2) 在空白單元格中直接根據指定的背景顏色對單元格求和。
應用 COUNTBYCELLCOLOR - SUMBYCELLCOLOR 分別為每種背景顏色設置功能,您將得到如下截圖所示的結果:

Kutools函數 包含許多內置函數,以幫助Excel用戶輕鬆計算,包括 計數/總和/平均可見細胞, 按單元格顏色計算/求和, 按字體顏色計算/總和, 計算字符, 按字體粗體計數等等。 免費試用!


使用Kutools for Excel根據特定填充顏色計算和求和單元格

使用上述用戶自定義功能,需要逐個輸入公式,如果有很多不同的顏色,這種方法會很繁瑣和耗時。 但如果你有 Kutools for Excel按顏色計數 實用程序,您可以快速生成彩色單元格的報告。 您不僅可以對有色單元進行計數和求和,還可以獲取有色域的平均值,最大值和最小值。

Kutools for Excel -包括多個用於Excel的300便捷工具。 全功能免費試用30天,無需信用卡! 立即行動吧

1。 選擇要使用的範圍,然後單擊 Kutools Plus > 按顏色計數,看截圖:

2。 而在中 按顏色計數 對話框,請按以下屏幕截圖顯示:
(1)選擇 標準格式 來自 顏色方法 下拉列表;
(2)選擇 背景 來自 計數類型 下拉列表。
(3)單擊“生成報告”按鈕。

備註:要按特定的條件格式顏色對彩色單元格進行計數和求和,請選擇 條件格式 來自 顏色方法 在上面的對話框中下拉列表,或選擇 標準和條件格式 從下拉列表中計算由指定顏色填充的所有單元格。

現在,您將獲得包含統計信息的新工作簿。 看截圖:

按顏色計數 feature按背景顏色或字體顏色計算(Count,Sum,Average,Max等)單元格。 免費試用!


相關文章:

如何根據Excel中的字體顏色計算/求和單元格?


演示:基於背景計算和求和單元格,條件格式化顏色:

Kutools for Excel 包含多個用於Excel的300便捷工具,可以在30天內不受限制地免費試用。 立即下載並免費試用!

Kutools for Excel解決了您的大多數問題,並使您的生產率提高了80%

  • 重用: 快速插入 複雜的公式,圖表 以及你以前用過的任何東西; 加密單元格 密碼; 創建郵件列表 並發送電子郵件...
  • 超級方程式酒吧 (輕鬆編輯多行文字和公式); 閱讀佈局 (輕鬆讀取和編輯大量單元格); 粘貼到過濾範圍...
  • 合併單元格/行/列 不丟失數據; 分裂細胞含量; 組合重複的行/列...防止重複的細胞; 比較範圍...
  • 選擇複製或唯一 行; 選擇空行 (所有細胞都是空的); 超級查找和模糊查找 在許多工作簿中; 隨機選擇......
  • 精確複製 多個單元格而不更改公式參考; 自動創建參考 多張表; 插入項目符號,複選框等等......
  • 提取文本,添加文本,按位置刪除, 刪除空間; 創建和打印分頁小計; 在單元格內容和註釋之間轉換...
  • 超級過濾器 (將過濾方案保存並應用到其他工作表); 高級排序 按月/週/日,頻率等; 特殊過濾器 用粗體,斜體......
  • 結合工作簿和工作表; 根據鍵列合併表; 將數據拆分為多個表格; 批量轉換xls,xlsx和PDF...
  • 超過300強大的功能。 支持Office / Excel 2007-2019和365。 支持所有語言。 在您的企業或組織中輕鬆部署。 全功能30天免費試用。
kte tab 201905

Office選項卡為Office提供選項卡式界面,使您的工作更輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,Publisher,Access,Visio和Project。
  • 在同一窗口的新選項卡中打開並創建多個文檔,而不是在新窗口中。
  • 通過50%提高您的工作效率,每天為您減少數百次鼠標點擊!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
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.
    Mori · 9 months 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.
    Troy Havard · 9 months 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 · 9 months 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.
      Troy Havard · 9 months 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 · 11 months 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.
      Arnier Hamz · 10 months 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 · 1 years ago
    This doesn't work at all. It's total BS.
  • To post as a guest, your comment is unpublished.
    Schmingy · 1 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 · 1 years ago
    i want to colour in excel by using if function.
  • To post as a guest, your comment is unpublished.
    Keerthi · 1 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 · 1 years ago
      I get an error when using ; but using, calculates fine?
  • To post as a guest, your comment is unpublished.
    Don Sison · 1 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 · 1 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 · 1 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 · 1 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 · 1 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 · 1 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 · 1 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 · 1 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 · 1 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 · 1 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 · 1 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 · 1 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.
    Kcc C · 1 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 · 1 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 · 1 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 · 2 years ago
    This has been so useful! Thanks very much for your help
  • To post as a guest, your comment is unpublished.
    Carolyn · 2 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 · 2 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 · 2 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 · 2 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 · 1 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.
    Carly Strang · 2 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 · 2 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 · 2 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.
        Liam Kennedy · 2 years ago
        Any news on this? I am having the same issue. Otherwise perfect :-)
        • To post as a guest, your comment is unpublished.
          Ryan · 2 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 · 2 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 · 2 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 · 2 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.
      Carly Strang · 2 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 · 2 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 · 2 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 · 2 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 · 2 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 · 2 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 · 2 years ago
    Very Helpful.

    Thanks a Lot.

    BR,
    RB.
  • To post as a guest, your comment is unpublished.
    Vamshi · 2 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 · 2 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 · 2 years ago
    Thanks for this. It's truely helpful to me!!!
  • To post as a guest, your comment is unpublished.
    Ramdzan · 2 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 · 2 years ago
    Jazak ALLAH it was very helpful
  • To post as a guest, your comment is unpublished.
    Jacqui · 2 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 · 2 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 · 2 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 · 3 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 · 3 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 · 3 years ago
    Fantastic! Worked very well.
  • To post as a guest, your comment is unpublished.
    Akshatha · 3 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 · 3 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 · 3 years ago
    Works Great !!!
    Thanks for posting!!
  • To post as a guest, your comment is unpublished.
    Kailas · 3 years ago
    Thanks! very useful function :)
  • To post as a guest, your comment is unpublished.
    Ranj · 3 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 · 3 years ago
    Worked like a charm when other codes would not! THANK YOU!
  • To post as a guest, your comment is unpublished.
    Saifi · 3 years ago
    Thankyou. very helpful information
  • To post as a guest, your comment is unpublished.
    Mike · 3 years ago
    It seems good, but I have an issue, in the code section, you say it does the same thing as the Color Count Function, however, this is not true. It looks at all my fields instead of just the visable ones, I need to be able to code this to look at only the visable cells.

    Any help would be great.
  • To post as a guest, your comment is unpublished.
    @1Ednut · 3 years ago
    Thank you very much! this worked first time for me!!
    wow... i just thought.. "excel should be able to do this" and voila

    thank you thank you thank you again!
  • To post as a guest, your comment is unpublished.
    Sunil · 3 years ago
    Yes it has worked and very good. but what about if I have to change the color or reduce the colour cells or increase the cell , the formula don't increase or decrease accordingly as like in pivot we refreseh the pivot and sheet get update according to change in main data.
  • To post as a guest, your comment is unpublished.
    Shaun · 3 years ago
    wow, got this working but have an issue. I can get the formula to work on the same tab; but it will not work when looking up colours on a different tab. The other tabs contain colours that are generated by conditioning format; has any one got any advice