How to Count Color Cells in Excel


Have you ever got into situation in office where you need to count the cells in Excel sheet with specific color? If yes then you can use following code which counts the number of cells with specific color (here it is yellow) and put the count in cell

It is worth to mention that the above code does not count the cells where colors are coming through conditional formatting. You can use DisplayFormat.Interior.Color to get the conditional formatting colors (DisplayFormat.Interior.Color works only on Excel 2010 or above) or read this post

Excel Tricks

Public Function CountColorCells(rng As Range) As Long
    'Variable declaration
    Dim lColorCounter As Long
    Dim rngCell As Range
    'loop throught each cell in the range
    For Each rngCell In rng
        'Checking Yellor color
        If Cells(rngCell.Row, rngCell.Column).Interior.Color = RGB(255, 255, 0) Then
            lColorCounter = lColorCounter + 1
        End If
    Next
    'Return the value
    CountColorCells = lColorCounter
End Function

To use this code in your Excel file, follow below steps:

  1. Open the Excel file where you want to count the color cells
  2. Press Alt+F11
  3. Insert a Module (Insert>Module) from menu bar
  4. Paste the code in the module
  5. Now type the formula in the cell where you want to get the count
  6. =CountColorCells(A2:A11)
  7. Done

Here I have counted the cells with yellow color. You can change RGB (#,#,#) code to count other colors. You can find RGB codes of any color using following steps

  1. Select the cell which contain the color you want to count
    Excel Tricks
  2. Right click and select ‘Format Cells…’
    Excel Tricks
  3. In the Format Cells dialog box go to ‘Fill’ tab and click on ‘More Colors…’
    Excel Tricks
  4. That’s all, in the ‘Color’ dialog box, you can view the RGB (Red, Green, Blue) codes of the color
    Excel Tricks

If you are look for a code to sum the cells based on it’s color then you can read this post.

Leave a Reply

avatar
VBA Code to Sum Cells by Color
VBA TRICKS
VBA Code to Sum Cells by Color

Recently some of our subscribers have requested us to share a VBA code that can sum the cells by its color. To help our subscribers and developers, we are sharing 2 codes that be used to sum the cells with specific color and returns the total sum of the matching color cells

FREE VBA UTILITIES
33
VBA Tool to Track Start and End Time (Time & Motion Tracker)

Here is one more wonderful free tool from ExcelSirJi.com which makes your life easy. Time & Motion Tracker helps you to track Start and End time of any type of transaction or activity. The good thing is, it is VBA based tool which helps you to protect from manual manipulation in the data by the user. It is also easy to use, just click on Start (shortcut: Ctrl+Shift+A) or Stop (Ctrl+Shft+S) buttons to record the time

VBA Code to Delete File
VBA TRICKS
VBA Code to Delete File

In this article we are going to show you how you can delete file or files using a single line of VBA code. 1. Delete a specific file from the folder, 2. Delete specific type of files from the folder, 3. Delete all files from the folder

error

Like the Article? Please spread the word :)

Facebook
Facebook
YouTube
YouTube
Pinterest
Pinterest
LinkedIn