跳到主要內容

如何在Excel中使用條件格式按顏色對單元格進行計數/求和?

在Excel中,您可以使用條件格式為某些單元格著色。 現在,本教程將告訴您一些便捷的方法,以便在Excel中使用條件格式快速按顏色對單元格進行計數或求和。

通過VBA按字體顏色和背景計數單元格

通過Kutools for Excel的條件格式按字體顏色對單元格進行計數/求和 好主意3      玩

通過背景顏色使用Kutools for Excel的條件格式對單元格進行計數/求和 好主意3      玩


箭頭藍色右氣泡 通過VBA按字體和背景色對單元格進行計數

在Excel中,只有VBA代碼可以基於特定的字體和背景顏色快速計數單元格。

1。 按 Alt + F11鍵 打開鑰匙 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊 並將以下VBA代碼複製並粘貼到彈出窗口中 模塊 窗口。

VBA:根據字體和背景顏色對單元格進行計數。

Sub DisplayFormatCount()
	'Updateby20150305
	Dim Rng As Range
	Dim CountRange As Range
	Dim ColorRange As Range
	Dim xBackColor As Long
	Dim xFontColor As Long
	On Error Resume Next
	xTitleId       = "KutoolsforExcel"
	Set CountRange = Application.Selection
	Set CountRange = Application.InputBox("Count Range :", xTitleId, CountRange.Address, Type: = 8)
	Set ColorRange = Application.InputBox("Color Range(single cell):", xTitleId, Type: = 8)
	Set ColorRange = ColorRange.Range("A1")
	xReturn        = 0
	For Each Rng In CountRange
		qqq           = Rng.Value
		xxx           = Rng.DisplayFormat.Interior.Color
		If Rng.DisplayFormat.Interior.Color = ColorRange.DisplayFormat.Interior.Color Then
			xBackColor   = xBackColor + 1
		End If
		If Rng.DisplayFormat.Font.Color = ColorRange.DisplayFormat.Font.Color Then
			xFontColor = xFontColor + 1
		End If
	Next
	MsgBox "BackColor is " & xBackColor & Chr(10) & "FontColor is " & xFontColor
End Sub

3。 點擊 按鈕或按下 F5 鍵運行代碼,然後在彈出對話框中選擇所需的範圍。 看截圖:
doc-count-condition-color-1

4。 點擊 OK,然後選擇一個要基於其字體和背景顏色進行計數的單元格。 看截圖:

doc-count-condition-color-2

5。 點擊 OK。 然後會彈出一個對話框,告訴您有多少個單元格具有與該範圍內所選單元格相同的背景色和字體顏色。

doc-count-condition-color-3


箭頭藍色右氣泡 通過Kutools for Excel的條件格式按字體顏色對單元格進行計數/求和

在Excel中,不能僅使用條件格式按字體顏色對單元格進行計數或求和。 但是,有一個方便的加載項稱為 Excel的Kutools 可以幫助您快速解決此問題 按顏色計數 功能。

Excel的Kutools, 與以上 300 方便的功能,使您的工作更加輕鬆。 

免費安裝 Kutools for Excel,請執行以下操作:

1.選擇要計數的範圍或使用條件格式按字體顏色對單元格求和,然後單擊 Kutools 加> 按顏色計數。 看截圖:

doc-count-condition-color-4

2.然後在 按顏色計數 對話框中選擇 條件格式上色方式 列出並 字體顏色類型 清單。 然後,您可以在對話框中查看計數和匯總的結果。 看截圖:

doc-count-condition-color-5

備註:如果要將計算結果作為報告輸出,可以單擊 生成報告我在n 按顏色計數 對話框,然後將在新工作簿中構建報告。 看截圖:

doc-count-condition-color-6      doc-count-condition-color-7


通過背景顏色使用Kutools for Excel的條件格式對單元格進行計數/求和

如果要使用條件格式按背景色對單元格進行計數或求和,也可以應用 按顏色計數 的效用 Excel的Kutools.

1.使用條件格式選擇要計數的範圍或按背景色求和的單元格,然後單擊 Kutools 加 > 按顏色計數.

免費安裝 Kutools for Excel,請執行以下操作:

2.然後在 按顏色計數 對話框中選擇 條件格式上色方式 列出並 背景 顏色類型 清單。 然後,您可以在對話框中查看計數和匯總的結果。 看截圖:

doc-count-condition-color-8

備註:如果要將計算結果作為報告輸出,可以單擊 生成報告 ,在 按顏色計數 對話框,然後將在新工作簿中構建報告。 看截圖:

doc-count-condition-color-9

單擊此處以獲取更多關於按顏色計數的信息。

小費。這款獨特的敏感免洗唇膜採用 Moisture WrapTM 技術和 Berry Mix ComplexTM 成分, 按顏色計數 在實用程式中,您還可以僅使用標準格式或標準格式和條件格式按背景顏色或字體顏色對儲存格進行計數/求和/平均。 如果您想在30天內無限制地應用按顏色計數, 請下載並立即免費試用。


箭頭藍色右氣泡 通過字體顏色或背景顏色計算單元格


最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (7)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi,

This is a great piece of VBA and works perfectly. Are you able to modify this code to make it a function and then be used as a formula?

e.g.
=DisplayFormatCount(A14:E14,A2,False) for counting background colour (Count Range, Colour Match Cell, type)

=DisplayFormatCount(C29:D29,A2,True) for counting font colour

I would like to you something like this for an input form of many tables and validation fields that are compulsory. I would then be able to count how many fields that have not been completed correctly.


Cheers
This comment was minimized by the moderator on the site
Could you please teach me VBA codes I would like to learn VBA using excel sheet
This comment was minimized by the moderator on the site
Chào bạn.

VBA đếm ô màu rất hay, tuy nhiên bạn có thể sửa giúp mình để kết quả không hiện thành msg box mà hiện luôn trên ô excel chỉ định được không? thêm cả hàm sum, average nữa thì càng tốt :D . Mail của mình là . Mình cám ơn.
This comment was minimized by the moderator on the site
Hi,
How do I modified the code for the cell contain conditional formatting? Because it count the background as "blank".


Thanks.
This comment was minimized by the moderator on the site
Sorry I have no idea about the VBA code.
This comment was minimized by the moderator on the site
May I congratulate you on a most easily understood and well written VBA program to perform such a simple task - i.e., count the number of cells with a specific color derived from Conditional Formatting. It beats the pants of the monster program by Pearson, and his does not even work, at least in Excel 2013. Nor do other supposed counting programs work that I have tried. Yours is the only one!! This worked perfectly. Thank you, thank you, thank you. Best Holiday Wishes, Mort in Dallas
This comment was minimized by the moderator on the site
hi


kindly send the above VBA code same code is I need please help.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations