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

If you’ve ever found yourself working with a massive Excel spreadsheet, you’ve probably wondered how to count highlighted cells. It’s not a feature built directly into Excel, but with a bit of creativity and the right techniques, it’s totally doable. This guide will show you how to count those highlighted cells step by step.

Counting Highlighted Cells in Excel

In this section, we’ll walk through the steps you’ll need to take to count highlighted cells in Excel. By the end, you’ll have a clear understanding of how to tackle this task effortlessly.

Step 1: Select the Data Range

Start by selecting the entire range of cells where you want to count highlighted cells.

It’s essential to know which cells you need to count. Click and drag to highlight the cells you’re interested in.

Step 2: Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.

The VBA editor is where you’ll write a small script to help count the highlighted cells. Don’t worry; it’s easier than it sounds!

Step 3: Insert a New Module

In the VBA editor, go to Insert > Module.

Modules are where you can write and store your VBA code. Think of them as blank pages where your script will live.

Step 4: Copy and Paste VBA Code

Copy and paste the following code into the module:

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

This code creates a function that counts cells based on the color you specify. It’s like a custom-built tool just for you.

Step 5: Close the VBA Editor

Close the VBA editor by clicking the X button or pressing Alt + Q.

Now, you’re back in your Excel workbook, and your custom function is ready to go.

Step 6: Use the Custom Function

Use the newly created function in a cell. Type =CountColoredCells(A1:A10, B1) where A1:A10 is your data range and B1 is a cell with the color you want to count.

By pointing to a cell with the desired color, you tell Excel exactly what you’re counting. This setup makes the function versatile.

After completing these steps, you’ll see the count of highlighted cells in your specified range in the cell where you entered the function. It’s just like magic!

Tips for Counting Highlighted Cells in Excel

  • Keep your VBA code saved in a safe place for easy reuse.
  • Update the range and color cell references as needed to apply the function to different parts of your spreadsheet.
  • Remember, this method only works for cells highlighted with a solid color fill.
  • Use the Format Painter tool to apply consistent highlighting across your data range.
  • Create a backup of your Excel file before tinkering with VBA scripts to prevent data loss.

Frequently Asked Questions

Can I count different colored cells separately?

Yes, you can modify the VBA function or use it multiple times with different color references.

What if my cells have conditional formatting?

This method only counts manually highlighted cells. Conditional formatting colors won’t be counted.

Does this work on Mac?

Yes, but ensure you have the VBA editor installed and enabled in your Excel version.

Can I count highlighted cells without VBA?

Not directly in Excel, but you can use manual methods like sorting and filtering by color.

Will this function slow down my spreadsheet?

For very large datasets, it might. Use the function sparingly and keep your data range as small as possible.


  1. Select the Data Range.
  2. Open the VBA Editor.
  3. Insert a New Module.
  4. Copy and Paste VBA Code.
  5. Close the VBA Editor.
  6. Use the Custom Function.


Counting highlighted cells in Excel can seem daunting if you’ve never dived into the world of VBA. But by following these steps, you can turn a complex task into a straightforward process. Whether it’s for work, school, or personal projects, knowing how to count those cells can save you tons of time and effort.

Excel is a powerful tool, and learning these tips and tricks can make you more efficient and effective in your tasks. Don’t be afraid to experiment with VBA and other advanced features to get the most out of your data. If you’re curious to learn more, there are countless resources online, from forums to tutorials.

Now that you’ve mastered this technique, why stop here? Excel offers a wealth of functions and features that can further streamline your workflow. Dive in, practice, and soon you’ll be an Excel wizard, turning tedious tasks into simple, automated processes. Happy Excel-ing!

Get Our Free Newsletter

How-to guides and tech deals

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