Home >Software Tutorial >Office Software >A simple tutorial on how to sum the sum based on cell color in Excel

A simple tutorial on how to sum the sum based on cell color in Excel

王林
王林forward
2024-03-30 11:21:29608browse

php editor Banana brings you a simple and easy-to-understand tutorial on how to filter and sum based on cell color in Excel. There may be a large amount of data in an Excel table, and quick filtering by cell color can help you process the data more efficiently. This tutorial will show you how to use Excel's filtering function to filter and operate based on cell color, allowing you to easily handle data processing work.

1. For example, there is a cell range as shown in the figure.

A simple tutorial on how to sum the sum based on cell color in Excel

2. We know that in the above table, some cells that are not adjacent have the same background color. The question now is how to sum cells with the same color. That is, sum the numbers in cells with the same color.

To solve this problem, you have to use VBA. Ordinary functions cannot complete this kind of summation.

First, in the Excel interface, press the key combination Alt F11

A Microsoft Visual Basic window will pop up. Then in this window, perform the menu operation: [Insert] → [Module], as shown in the figure.

A simple tutorial on how to sum the sum based on cell color in Excel

3. Then you will see a small white form of [Module 1 (Code)]. This form is used to enter VBA code. As shown in the picture.

A simple tutorial on how to sum the sum based on cell color in Excel

4. Just enter the VBA code directly in the small input form. As shown in the picture above, please note that you must follow the input completely and make sure you don’t make a mistake.

To make it easier for everyone to learn, the code is pasted as follows:

A simple tutorial on how to sum the sum based on cell color in Excel

After inputting, close the Microsoft Visual Basic window, return to the EXCEL window, and then perform the operations on Excel A save operation.

As shown in the figure, if you want to count the sum of cells of which color, just use the function name of the above code to make statistics.

A simple tutorial on how to sum the sum based on cell color in Excel

5. For example, if we want to count the sum of red cells, then enter the code as shown above.

=MyColorSum(C2,A1:C10)

The above is the detailed content of A simple tutorial on how to sum the sum based on cell color in Excel. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:zol.com.cn. If there is any infringement, please contact admin@php.cn delete