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
- How to split 1 cell into 2 cells in Excel - Split cells in Excelhow to split 1 cell into 2 cells in excel - split cells in excel. depending on different purposes, you want to split a cell into two cells to enter two different data in one cell and still be able to calculate normally as other cells.
- 3 ways to calculate totals in Excelto calculate totals on excel, users can use them in three different ways, based on spreadsheets, autosum functions or sum functions with large data areas.
- Change color between different lines in Microsoft Excelselecting and shedding colors separately for data areas is especially useful when you have a spreadsheet with lots of different statistics. in the following article, we will show you some steps to do this in microsoft excel ...
- Format Excel 2007 spreadsheetsometimes you want to split data in one cell into two or more cells. you can do this easily by using the convert text to columns wizard.
- Delete background colors and backgrounds in Exceldelete background colors and backgrounds in excel. in excel, you can use images as the background for a spreadsheet for the purpose of displaying only, since it is not printed. but if you use background color, it will be printed with data in exc worksheet
- Calculate the total value of the filtered list in Excelfilter is a very useful and easy to use feature in microsoft excel. with filters, you can quickly limit data to only show the necessary information. however, how to calculate the total value of the filtered list? the following article will help you answer the above question.
- How to create spaces between letters and cell borders in Exceladding spaces between text and cell borders in excel makes it easier to read the document.
- How to change the background color in Photoshopchanging the background color in photoshop can be used with existing photos or new images.
- SUM function in Excel: How to use SUM to calculate totals in Excel - SUM function in Excelthe sum function in excel is quite commonly used. below are details on how to calculate the sum function and related issues in microsoft excel.
- How to delete a background color in a Word document?it's helpful to dump the background color in the field so you can easily find the fields in your document. however, if you share documents with others or use them in a presentation ... you should remove the background color.