How to Count Coloured Cells in Excel: A Step-by-Step Guide

Counting Colored Cells in Excel

Ever wondered how to count colored cells in Excel? It’s simpler than you think! With a few easy steps, you can quickly tally up those highlighted cells. Whether you’re dealing with different categories, priorities, or any other color-coded system, this guide will turn you into an Excel whiz in no time.

How to Count Colored Cells in Excel

Let’s dive into the nitty-gritty of counting colored cells in Excel. We’ll use a combination of functions and a little trick with VBA (Visual Basic for Applications). Trust me, by the end of this, you’ll be confidently counting colored cells.

Step 1: Open Excel and Prepare Your Data

First, open Excel and ensure your data is organized.

Organized data makes it easier to identify and count the colored cells. If your cells are scattered all over the place, consider arranging them in a more structured manner.

Step 2: Press ALT + F11 to Open VBA Editor

Next, press ALT + F11 to open the VBA editor.

The VBA editor is where you can write small programs to help Excel do more advanced tasks. Don’t worry; you won’t need to write a whole program—just a small piece of code.

Step 3: Insert a Module

Then, click Insert and select Module.

Inserting a module creates a space where you can paste or write your VBA code. Think of it as opening a new document in Word.

Step 4: Paste the VBA Code

Next, paste the following VBA code into the module editor:

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

This VBA code sets up a function that will count cells in a specified range that match the color of another specified cell. It’s like telling Excel, "Hey, count how many cells are the same color as this one."

Step 5: Save and Close the VBA Editor

Now, save and close the VBA editor by clicking the Save icon and then closing the window.

Saving your work ensures the function is ready to be used in your Excel worksheet. Closing the editor takes you back to your familiar Excel interface.

Step 6: Use the Function in Your Worksheet

Finally, in your worksheet, use the function like this: =CountColoredCells(A1:A10, B1) where A1:A10 is your range and B1 is the cell with the color you’re counting.

This is where the magic happens. Entering this formula will give you the count of cells within the specified range that match the color of the reference cell.

After following these steps, your Excel sheet will display the count of the colored cells in the specified range. You can now easily keep track of colored categories or priorities with just a glance.

Tips for Counting Colored Cells in Excel

  1. Back Up Your Data: Always save a copy of your work before using VBA, just in case.
  2. Use Named Ranges: Naming your ranges can make the function easier to understand and manage.
  3. Color Consistency: Ensure the colors are consistent to avoid counting errors.
  4. Test on a Small Range First: Before applying to a large dataset, test the function on a smaller range to ensure it works correctly.
  5. Excel Versions: Make sure to use a version of Excel that supports VBA, as some online or mobile versions may not.

Frequently Asked Questions

Can I count cells with multiple colors at once?

At the moment, the function only counts cells of one color at a time. You would need to run the function separately for each color.

What if my cells are shaded with gradient colors?

The function counts solid colors only. Gradient-shaded cells won’t be counted correctly.

Do I need to enable macros for this to work?

Yes, since VBA is considered a macro, you will need to enable macros in Excel for this function to work.

Can I use this function on any worksheet?

Yes, the function can be used on any worksheet within the Excel workbook where the module was inserted.

Will this function slow down my Excel?

If you’re using it on a very large dataset, it might take a bit of time, but generally, it runs efficiently.


  1. Open Excel and prepare your data.
  2. Press ALT + F11 to open VBA editor.
  3. Insert a module.
  4. Paste the VBA code.
  5. Save and close the VBA editor.
  6. Use the function in your worksheet.


Counting colored cells in Excel can be a game-changer for managing your data. Whether you’re sorting tasks by priority, tracking categories, or just curious about the distribution of colors, this method can simplify your workflow.

With the steps and tips provided, you should now be able to count colored cells like a pro. Don’t stop here—Excel has a plethora of functions and features waiting to be explored. Happy counting!

Get Our Free Newsletter

How-to guides and tech deals

You may opt out at any time.
Read our Privacy Policy