How to count colored cells in excel
Tutor 5 (54 Reviews)
Excel Tutor
Still stuck with a Excel question
Ask this expertAnswer
Counting colored cells in Excel cannot be done directly with a standard formula. You can use either a filter method, SUBTOTAL with filtering, or a VBA (macro) function to achieve this.
1. Using the Filter Method
-
Select the range containing colored cells.
-
Go to the Data tab and click Filter.
-
Click the drop-down arrow in the column with colored cells.
-
Choose Filter by Color and select the color you want to count.
-
Excel will display only the rows with that color.
-
Look at the status bar at the bottom-right corner of Excel to see the count of visible cells.
This method works best for small datasets and does not require formulas.
2. Using the SUBTOTAL Function with Filtering
-
Apply a filter to your data using the Data → Filter option.
-
Filter the rows by the desired color using Filter by Color.
-
Use the formula:
=SUBTOTAL(103, A2:A100)
-
103counts only visible cells (ignores hidden rows). -
A2:A100is the range of the column with colored cells.
This method counts the cells automatically after applying the color filter.
3. Using a VBA Function
You can create a custom function to count colored cells.
-
Press Alt + F11 to open the VBA editor.
-
Go to Insert → Module.
-
Paste the following code:
Function CountColoredCells(rng As Range, color As Range) As Long
Dim cell As Range
Dim count As Long
count = 0
For Each cell In rng
If cell.Interior.Color = color.Interior.Color Then
count = count + 1
End If
Next cell
CountColoredCells = count
End Function
-
Close the VBA editor.
-
Use the function in a cell like this:
=CountColoredCells(A2:A100, C1)
-
A2:A100is the range of cells to check. -
C1is a cell with the color you want to count.
The function returns the total number of cells with the same background color as C1.
4. Notes for Windows vs Mac
-
Windows: Use Alt + F11 to open VBA.
-
Mac: Use Option + F11 to open VBA.
-
The rest of the steps are the same on both platforms.
This provides a precise, flexible way to count colored cells for both small and large datasets, ensuring accurate results for reporting or analysis.
. Was this Helpful?Get Online Tutoring or Questions answered by Experts.
You can post a question for a tutor or set up a tutoring session
Answers · 1
Why are margins not working
Answers · 1
Why is page layout not working
Answers · 1
How to print repeated rows on top in excel
Answers · 1
How to print header on each page
Answers · 1