Sum spesific cell colour

joacro

Board Regular
Joined
Jun 24, 2010
Messages
158
Hi there
I have a worksheet where I need to sum all the values of a spesific font colour of a colour

The cell that needs to desplay the value is D42 (this can change once more rows are inserted above)

The collum that needed is D

Hope someone can help me with this. It is very urgent

Regards
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi,

You can use the following user defined function:



Code:
'Function to sum the cells inside a range if the font is a certain colour
Function sumfont(Colour_Sample As Range, Cell_Range As Range)
Dim rCell As Range
Dim lCol As Long
Dim lResult As Long
Application.Volatile
lCol = Colour_Sample.Font.ColorIndex

For Each rCell In Cell_Range
If rCell.Font.ColorIndex = lCol Then
lResult = rCell + lResult
End If

Next rCell

sumfont = lResult

End Function




Paste it into a new VBA module and to use, enter the formula:

=sumfont(colour_sample,cell_range)

Note:

colour_sample is a cell containing the colour font you want to sum (Eg. if you want to count all red font values within the cell range, choose any cell with red font as the colour_sample).

cell_range is the range containing the data you want to sum if the font colour matches the colour_sample (column D in your scenario).

Thanks
 
Upvote 0
I've noticed that if cell values have partial numbers, i.e. "1.5" or "1.25" that the SumFont is ignoring the values after the decimal in the final SUM count!
Anybody know why this is happening?
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,820
Members
449,469
Latest member
Kingwi11y

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