Calculate by cell background color in Excel
The following article details how to sum data cells by cell background color in Excel by building a macro function to calculate the cell background color.
Example: The colors have corresponding values. Sum the values corresponding to the cell's background color.
Step 1: Press the key combination Alt + F11 to open VBA 's working window -> Go to Insert tab -> Module .
Step 2: Build the function to calculate the total by color (named SumByColor ). Enter the following code into the newly created Module:
Function SumByColor (cellColor As Range, rRange As Range) Dim tong As Long Dim mau_sac As Integer mau_sac = cellColor.Interior.ColorIndex For Each c In rRange If c.Interior.ColorIndex = mau_sac Then tong = WorksheetFunction.Sum (c, tong) End If Next c SumByColor = tong End Function
Note: Remember the name of the function you just created.
Step 3: Go back to the Excel File to calculate and select the SumByColor function as shown below:
Step 4: The SumByColor function (cellColor, rRange) has 2 arguments that are the color value of the cell and the data range to be calculated -> Enter the statement as shown:
Step 5: Convert the cell address to absolute address, highlight the address area and press F4. (You should do this step to avoid errors).
Finally Copy the formula to the remaining cells -> Result:
Good luck!
You should read it
- Instructions to change the cell background color (Cell) in Excel
- Delete background colors and backgrounds in Excel
- Change color between different lines in Microsoft Excel
- How to automatically color rows and columns in Excel
- How to use the SUM function to calculate totals in Excel
- Format borders and background colors for tables in Excel
- Instructions to add background color to each cell in the table on Word
- How to use themes in Excel
May be interested
- Instructions for using PivotTable in Excel - How to use PivotTablea pivottable is a tool used to analyze data from different angles and requirements from a list or a table. from the initial huge data block, the pivottable can help you to aggregate data in groups and collapse data as required.
- Instructions to insert Textbox in Excelthe following article details how to insert textbox in excel.
- Find and Replace functions in Excelthe following article details how to use find and replace in excel.
- Instructions for using the Find and Replace functions in Excelwith excel spreadsheets with large amounts of data, it is very time consuming to search and replace data cells manually. the following article details how to use the find and replace function in excel.
- Index and Match functions in Excelthe following article gives detailed instructions on how to use the index and match functions in excel. use these functions to help you find the exact value on any column and row.
- Convert Word to PDF with Office 2013with very simple operation, without using any intermediary software, you can create pdf files on word 2013 yourself. for example, converting .docx files to pdf using office 2013 as follows: