sum by color

salth2o

New Member
Joined
Aug 10, 2006
Messages
10
I'm using the following code which I know works...but for some reason it's NOT working in my spreadsheet. It's adding the entire column regardless of the color I've specified in the range cell. Any thoughts?

Function SumColor(rColor As Range, rSumRange As Range)
'Written by Ozgrid Business Applications
'www.ozgrid.com
Dim rCell As Range
Dim iCol As Integer
Dim vResult
iCol = rColor.Interior.ColorIndex

For Each rCell In rSumRange
If rCell.Interior.ColorIndex = iCol Then
vResult = WorksheetFunction.Sum(rCell) + vResult
End If
Next rCell

SumColor = vResult
End Function
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Are your cells being colored by conditional formatting or just a fill color?
 
Upvote 0
Have to tried refreshing the formula and see if that makes any difference, sometimes it doesn't calculate automatically for a reason unknown to myself.
 
Upvote 0
You could try a complete re-calc by using Control+Alt+F9. IF that fixes it, it may be what jdc was referring to and then in the function you can add:

Application.Volatile = True

This will make it volatile and calculate with every change int he workbook.

Hope that helps.
 
Upvote 0
I've refreshed the calculating field. Thanks for that tip though! Still doesn't change the outcome. Cells are formatted green by text, not fill.
 
Upvote 0
This function is looking at fill color, not text color? Do you need text color?

If so try:

Code:
Function SumColor(rColor As Range, rSumRange As Range)
'Written by Ozgrid Business Applications
'www.ozgrid.com
Dim rCell As Range
Dim iCol As Integer
Dim vResult
iCol = rColor.Font.ColorIndex

For Each rCell In rSumRange
If rCell.Font.ColorIndex = iCol Then
vResult = WorksheetFunction.Sum(rCell) + vResult
End If
Next rCell

SumColor = vResult
End Function
This is checking font color against a cell in the formula signifying font color, but maybe you want to use a cells fill color to sum on?
 
Upvote 0
That worked but my cell that is using the "green" to tell it which color to sum...I had to change the font color of that cell to green instead of just the word green.

Still learning........

Thanks!!!!
 
Upvote 0
Which way or how do you want it? It isn't as easy to use the word, but can be done if you would like it that way?
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,500
Members
449,090
Latest member
RandomExceller01

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