亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Table of Contents
Count cells by fill color
Count cells by font color
How to sum by color in Excel
Sum values by font color
Count and sum by color across entire workbook
How to count colored cells in entire workbook
Home Software Tutorial Office Software Excel: count and sum cells by color

Excel: count and sum cells by color

May 28, 2025 am 09:34 AM

Here is the pseudoriginaled content, maintaining the original structure, language, and image positions:


In this article, you will discover innovative methods to sum and count cells in Excel based on their color. These approaches work for cells colored manually or via conditional formatting across all versions of Excel from 2010 through Excel 365.

Despite Excel's wide array of functions for various tasks, none can compute cells based on their color. Apart from third-party tools, the most efficient solution is creating your own functions. Don’t worry if you’re unfamiliar with user-defined functions or have never encountered the term before. The functions are pre-written and tested by us. All you need to do is add them to your workbook!

How to count cells by color in Excel ------------------------------------

Below, you'll find the codes for two custom functions (commonly referred to as user-defined functions or UDFs). The first function counts cells with a specific fill color, while the other counts cells based on font color. Both were crafted by Alex, one of our top Excel experts.

Custom functions to count by color in Excel Function CountCellsByColor(data_range As Range, cell_color As Range) As Long Dim indRefColor As Long Dim cellCurrent As Range Dim cntRes As Long Application.Volatile cntRes = 0 indRefColor = cell_color.Cells(1, 1).Interior.Color For Each cellCurrent In data_range If indRefColor = cellCurrent.Interior.Color Then cntRes = cntRes 1 End If Next cellCurrent CountCellsByColor = cntRes End Function Function CountCellsByFontColor(data_range As Range, font_color As Range) As Long Dim indRefColor As Long Dim cellCurrent As Range Dim cntRes As Long Application.Volatile cntRes = 0 indRefColor = font_color.Cells(1, 1).Font.Color For Each cellCurrent In data_range If indRefColor = cellCurrent.Font.Color Then cntRes = cntRes 1 End If Next cellCurrent CountCellsByFontColor = cntRes End Function Once the functions are added to your workbook, they will perform their calculations in the background, and you can use them just like any other native Excel function. From the end-user perspective, the functions appear as follows:

Count cells by fill color

To count cells with a specific background color, use this function:

CountCellsByColor(data_range, cell_color) Where:

  • Data_range is the range in which to count cells.
  • Cell_color is a reference to the cell with the target fill color.

To count cells of a specific color within a given range, follow these steps:

  1. Add the CountCellsByColor function code to your workbook.
  2. Begin typing the formula in the cell where you want the result to appear: =CountCellsByColor(
  3. For the first argument, input the range where you wish to count colored cells.
  4. For the second argument, provide the cell with the target color.
  5. Press Enter. Done!

For example, to determine how many cells in range B3:F24 share the same color as H3, the formula is:

=CountCellsByColor(B3:F24, H3)

In our sample dataset, cells with values less than 150 are colored yellow, and those with values greater than 350 are green. The function easily calculates both counts:

Excel: count and sum cells by color

Count cells by font color

If your cell values have different font colors, you can count them using this function:

CountCellsByFontColor(data_range, font_color) Where:

  • Data_range is the range in which to count cells.
  • Font_color is a reference to the cell with the sample font color.

For example, to find the number of cells in B3:F24 with the same font color as H3, the formula is:

=CountCellsByFontColor(B3:F24, H3)

Excel: count and sum cells by color

Tip. If you prefer to rename the functions, feel free to modify the names directly in the code.

How to sum by color in Excel

To sum colored values, add the following two functions to your workbook. Similar to the previous example, the first handles fill color, and the other deals with font color.

Custom functions to sum by color in Excel Function SumCellsByColor(data_range As Range, cell_color As Range) Dim indRefColor As Long Dim cellCurrent As Range Dim sumRes Application.Volatile sumRes = 0 indRefColor = cell_color.Cells(1, 1).Interior.Color For Each cellCurrent In data_range If indRefColor = cellCurrent.Interior.Color Then sumRes = WorksheetFunction.Sum(cellCurrent, sumRes) End If Next cellCurrent SumCellsByColor = sumRes End Function Function SumCellsByFontColor(data_range As Range, font_color As Range) Dim indRefColor As Long Dim cellCurrent As Range Dim sumRes Application.Volatile sumRes = 0 indRefColor = font_color.Cells(1, 1).Font.Color For Each cellCurrent In data_range If indRefColor = cellCurrent.Font.Color Then sumRes = WorksheetFunction.Sum(cellCurrent, sumRes) End If Next cellCurrent SumCellsByFontColor = sumRes End Function ### Sum values by cell color

To sum by fill color in Excel, use this function:

SumCellsByColor(data_range, cell_color) Where:

  • Data_range is the range in which to sum values.
  • Cell_color is a reference to the cell with the fill color of interest.

For example, to add up the values of all cells in B3:F24 shaded with the same color as H3, the formula is:

=SumCellsByColor(B3:F24, H3)

Excel: count and sum cells by color

Sum values by font color

To sum numeric values with a specific font color, use this function:

SumCellsByFontColor(data_range, font_color) Where:

  • Data_range is the range in which to sum cells.
  • Font_color is a reference to the cell with the target font color.

For instance, to add up all the values in cells B3:F24 with the same font color as the value in H3, the formula is:

=SumCellsByFontColor(B3:F24, H3)

Excel: count and sum cells by color

Count and sum by color across entire workbook

To count and sum cells of a certain color in all sheets of a given workbook, we’ve created two separate functions named WbkCountByColor and WbkSumByColor. Here’s the code:

Custom functions to count and sum by color across workbook Function WbkCountByColor(cell_color As Range) Dim vWbkRes Dim wshCurrent As Worksheet Application.ScreenUpdating = False Application.Calculation = xlCalculationManual vWbkRes = 0 For Each wshCurrent In Worksheets wshCurrent.Activate vWbkRes = vWbkRes CountCellsByColor(wshCurrent.UsedRange, cell_color) Next Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic WbkCountByColor = vWbkRes End Function Function WbkSumByColor(cell_color As Range) Dim vWbkRes Dim wshCurrent As Worksheet Application.ScreenUpdating = False Application.Calculation = xlCalculationManual vWbkRes = 0 For Each wshCurrent In Worksheets wshCurrent.Activate vWbkRes = vWbkRes SumCellsByColor(wshCurrent.UsedRange, cell_color) Next Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic WbkSumByColor = vWbkRes End Function Note. To make the functions’ code more concise, we refer to the previously discussed functions that count and sum within a specified range. Thus, for the “workbook functions” to work, be sure to add the code of the CountCellsByColor and SumCellsByColor functions to your Excel too.

How to count colored cells in entire workbook

To find out how many cells of a particular color exist in all sheets of a given workbook, use this function:

WbkCountByColor(cell_color) The function takes just one argument—a reference to any cell filled with the color of interest. Therefore, a practical formula might look

The above is the detailed content of Excel: count and sum cells by color. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the meeting time limit for the free version of Teams? What is the meeting time limit for the free version of Teams? Jul 04, 2025 am 01:11 AM

MicrosoftTeams’freeversionlimitsmeetingsto60minutes.1.Thisappliestomeetingswithexternalparticipantsorwithinanorganization.2.Thelimitdoesnotaffectinternalmeetingswhereallusersareunderthesameorganization.3.Workaroundsincludeendingandrestartingthemeetin

how to group by month in excel pivot table how to group by month in excel pivot table Jul 11, 2025 am 01:01 AM

Grouping by month in Excel Pivot Table requires you to make sure that the date is formatted correctly, then insert the Pivot Table and add the date field, and finally right-click the group to select "Month" aggregation. If you encounter problems, check whether it is a standard date format and the data range are reasonable, and adjust the number format to correctly display the month.

How to Fix AutoSave in Microsoft 365 How to Fix AutoSave in Microsoft 365 Jul 07, 2025 pm 12:31 PM

Quick Links Check the File's AutoSave Status

how to repeat header rows on every page when printing excel how to repeat header rows on every page when printing excel Jul 09, 2025 am 02:24 AM

To set up the repeating headers per page when Excel prints, use the "Top Title Row" feature. Specific steps: 1. Open the Excel file and click the "Page Layout" tab; 2. Click the "Print Title" button; 3. Select "Top Title Line" in the pop-up window and select the line to be repeated (such as line 1); 4. Click "OK" to complete the settings. Notes include: only visible effects when printing preview or actual printing, avoid selecting too many title lines to affect the display of the text, different worksheets need to be set separately, ExcelOnline does not support this function, requires local version, Mac version operation is similar, but the interface is slightly different.

How to change Outlook to dark theme (mode) and turn it off How to change Outlook to dark theme (mode) and turn it off Jul 12, 2025 am 09:30 AM

The tutorial shows how to toggle light and dark mode in different Outlook applications, and how to keep a white reading pane in black theme. If you frequently work with your email late at night, Outlook dark mode can reduce eye strain and

How to Screenshot on Windows PCs: Windows 10 and 11 How to Screenshot on Windows PCs: Windows 10 and 11 Jul 23, 2025 am 09:24 AM

It's common to want to take a screenshot on a PC. If you're not using a third-party tool, you can do it manually. The most obvious way is to Hit the Prt Sc button/or Print Scrn button (print screen key), which will grab the entire PC screen. You do

Where are Teams meeting recordings saved? Where are Teams meeting recordings saved? Jul 09, 2025 am 01:53 AM

MicrosoftTeamsrecordingsarestoredinthecloud,typicallyinOneDriveorSharePoint.1.Recordingsusuallysavetotheinitiator’sOneDriveina“Recordings”folderunder“Content.”2.Forlargermeetingsorwebinars,filesmaygototheorganizer’sOneDriveoraSharePointsitelinkedtoaT

how to find the second largest value in excel how to find the second largest value in excel Jul 08, 2025 am 01:09 AM

Finding the second largest value in Excel can be implemented by LARGE function. The formula is =LARGE(range,2), where range is the data area; if the maximum value appears repeatedly and all maximum values ??need to be excluded and the second maximum value is found, you can use the array formula =MAX(IF(rangeMAX(range),range)), and the old version of Excel needs to be executed by Ctrl Shift Enter; for users who are not familiar with formulas, you can also manually search by sorting the data in descending order and viewing the second cell, but this method will change the order of the original data. It is recommended to copy the data first and then operate.

See all articles