Summing Color Filled cells only

bobgrand

Active Member
Joined
Apr 14, 2008
Messages
252
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have a rather large list of values that are color filled with a varity of different colors. Is there a way to sum only the cells that are color filled?

Any help would be greatly appreciated.

Bob
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try this custom function.
VBA Code:
Function SumColorFilled(rng As Range) As Double
    Dim cell As Range
    Dim s As Double
    s = 0

    For Each cell In rng
        If cell.Interior.ColorIndex <> xlNone Then
            s = s + cell.Value
        End If
    Next cell

    SumColorFilled = s
End Function
Book1
BCDE
1316825
1459
Sheet4
Cell Formulas
RangeFormula
E13E13=SumColorFilled(B13:C14)
 
Upvote 0
Hi Cubic,

I am fairly new to the Macro/VBA world so please bear with me.

Not sure what I am doing wrong here. I built a quick test sheet just as you show. I Copy and pasted the VBA and closed the editor. Before I highlight any values there is an error in E13 that shows "#NAME?" After I highlight 2 of the 4 cells the error remains "#NAME?" I feel this is so simple I am missing something. Do you have any guidance?

To add to this Highlights can be different from report to report. This report could have 12 different highlights and the next report could have 30.

As always any help is greatly appreciated.
 
Upvote 0
Did you paste the code in a regular module or the worksheet module?
 
Upvote 0
You're welcome
Btw, I think the code could do with the line in red below being added

Rich (BB code):
Function SumColorFilled(rng As Range) As Double
    Dim cell As Range
    Dim s As Double
    
    Application.Volatile
    
    s = 0

    For Each cell In rng
        If cell.Interior.ColorIndex <> xlNone Then
            s = s + cell.Value
        End If
    Next cell

    SumColorFilled = s
End Function
 
Upvote 0
While I do agree with @MARK858 that we should add Application.Volatile, note that it'll make the function significantly slower and taxing on your workbook (especially when you have a large list of values). Is there a rule for the highlighted values?
 
Upvote 0
I am not sure of the rule for the highlighted values. For the most part I can now show them what I learned here to see if it will help them.

Thank you both for you guidance.
I learn a little bit more every day.
 
Upvote 0
I would like to expand on this if you don't mind.

I am being asked if there is a way to get totals by specific color, Yellow, Green, Blue, Purple, etc..

In column Q there are Dollar Totals. Colors are being used to identify which is most important to least important. These colors can change over time. Can the totals be calculated in Column S, Rows 2,3,4,5,6 as shown in the image attached.

As always thank you for any help that is offered.
 

Attachments

  • Totals_By_Color.jpg
    Totals_By_Color.jpg
    55.4 KB · Views: 12
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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