By: Shamima Sultana

In reply to galwin.

Hello Galwin,

Congratulations on your new job as a Document Controller! I understand how time-consuming it can be to count colored cells manually. Fortunately, Excel offers a few ways to automate this task.

If you want the count to update automatically whenever cell colors change, I recommend using VBA (Visual Basic for Applications) since regular Excel formulas don’t dynamically update based on color changes. Here’s a simple VBA solution:

1. Press Alt + F11 to open the VBA editor.
2. Go to Insert > Module to add a new module.
Paste this code:

Function CountColoredCells(rng As Range, colorCell As Range) As Long
Dim count As Long
Application.Volatile
For Each cell In rng
If cell.Interior.Color = colorCell.Interior.Color Then count = count + 1
Next cell
CountColoredCells = count
End Function

Press Ctrl + S to save the macro and close the editor.
In your Excel sheet, use the formula like this:
=CountColoredCells(A1:D10, F1)
Replace A1:D10 with your data range and F1 with a cell that has the color you want to count.

Automatic Update
To make sure the count updates when colors change:

Press Alt + F11, go to ThisWorkbook in the editor, and paste this code:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.Calculate
End Sub

This ensures the function recalculates every time you update your worksheet.

Regards
ExcelDemy