sum of the same formated numbers

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
826
Office Version
  1. 365
Platform
  1. Windows
Hi
I have the following code in a module
HTML:
Function ColorSum(ColorCell As Range, SumRange As Range) As Variant
Dim Cell As Range
For Each Cell In SumRange
If Cell.Font.ColorIndex = ColorCell.Font.ColorIndex Then
ColorSum = Cell + ColorSum
End If
Next
ColorSum = ColorSum
End Function

In a cell I have

HTML:
=colorSum(BG1, cashweek4)

Where BG1 is formatted Black, and “cashweek4” is the range that I enter numbers.<?xml:namespace prefix = o /><o:p></o:p>
<o:p></o:p>
If I enter a number in black (in the range) the formula works fine. (it adds all the black numbers). If I change the entered number to a different color, the formula still thinks it’s black. If I start with a different color and then change it to black, the formula doesn’t recognize it. I have to retype the formula in the cell to get the proper solution. I tried to use F9, but it doesn’t help.<o:p></o:p>
What Am I doing wrong?


Mike :confused:<o:p></o:p>

<o:p></o:p>
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try

Rich (BB code):
Function ColorSum(ColorCell As Range, SumRange As Range) As Variant
Application.Volatile
Dim Cell As Range
For Each Cell In SumRange
If Cell.Font.ColorIndex = ColorCell.Font.ColorIndex Then
ColorSum = Cell + ColorSum
End If
Next
ColorSum = ColorSum
End Function

You will still need to press F9.
 
Upvote 0
Hi Pete
Thanks. Since I have to press F9, I'll write an event macto for it. :biggrin:



Can't make out the name on the bottle.
Mike :beerchug:
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,451
Members
452,915
Latest member
hannnahheileen

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