SUM column ranges skipping cells with background color

pban92

Board Regular
Joined
Feb 26, 2010
Messages
88
Office Version
  1. 2016
Platform
  1. Windows
I have two columns - Name and value. When I want to SUM the range using SUM function, I get total sum. value.

But what I'd like to do is my total sum will be auto updated if I fill any cell with a color. In the example snippet (attached),
when I fill cell D12 with any color for example yellow in this case, the total value 6 in G13 needs to be updated to 5.

Is there any way to get this done?

Many thanks!
 

Attachments

  • Capture1.PNG
    Capture1.PNG
    14.4 KB · Views: 30

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Just clicking the cell and filling cell with yellow randomly.
 
Upvote 0
There isnt a standard excel function that will get you the FILL color of a cell. You can create a user defined function
in VBA and use that as part of your process.

If you have a "rule" you go by to color the cells, you should use that rule as the basis for selecting your data to SUM.
And, if you'd like the forum to try to solve your problem, please use the xl2bb add in (Link below) to post a mini workbook of your data.
Or at least post a table. WIth images, the forum needs to recreate your data, which is time consuming and could have errors.
Please help the forum help you.

Thanks in advance,
 
Upvote 0
Just clicking the cell and filling cell with yellow randomly.

If you are doing this just for curiosity and testing. I suggest making another column with "YES" or "NO" as a drop down using data validation, and include that in your SUMIF calculation.
 
Upvote 0
This will sum all the cells which are default color. Just open the vba editor and paste this in there then use this as a regular function of excel.
VBA Code:
Function COLORC(rng As Range)
            Dim rng2 As Range
            Dim c As Double
            For Each rng2 In rng
                    If rng2.Interior.ColorIndex = xlNone Then
                            c = c + rng2.Value
                    End If
            Next rng2
            COLORC = c
End Function

1680365011990.png
 
Upvote 0
This will sum all the cells which are default color. Just open the vba editor and paste this in there then use this as a regular function of excel.
VBA Code:
Function COLORC(rng As Range)
            Dim rng2 As Range
            Dim c As Double
            For Each rng2 In rng
                    If rng2.Interior.ColorIndex = xlNone Then
                            c = c + rng2.Value
                    End If
            Next rng2
            COLORC = c
End Function

View attachment 88846

Many thanks Shiningamilight
and others for your response.

However, I have two more follow up questions (attached my micro enabled spreadsheet)

1. In my example, I need to highlight the fruit type with yellow, not the quantity itself and get the total sum.
2. Is there a way to auto update or refresh as soon as cells are updated with colors?

Sorry can't upload mini-sheet as I'm using corporate laptop not allowing XL2BB.
 

Attachments

  • Capture1.1.PNG
    Capture1.1.PNG
    8.7 KB · Views: 27
Upvote 0
Many thanks Shiningamilight
and others for your response.

However, I have two more follow up questions (attached my micro enabled spreadsheet)

1. In my example, I need to highlight the fruit type with yellow, not the quantity itself and get the total sum.
2. Is there a way to auto update or refresh as soon as cells are updated with colors?

Sorry can't upload mini-sheet as I'm using corporate laptop not allowing XL2BB.
Here is my excel copy:

FruitQuantity
Apple1
Orange2
Grape3Total Sum
6
Banana10
Orange20
Blue30
60
 
Upvote 0

Forum statistics

Threads
1,224,727
Messages
6,180,583
Members
452,988
Latest member
wcself81

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top