Sum the values of cells based on fontcolor

F

fam.Hougaard

I have a worksheet and a need to sum cells with a certain font-color.

I have a number of rows with tasks listed. In the coloums i have 12
months and i the cells are workhours per task per month placed
registrered.

A task can be given a status like this :1) not stated = red, 2 started
= orange,
done = green.

I need to have 3 sums to the right of each tast. A sum for the "Not
started" hours (=red), a sum for the "Stated" hours (=orange) and a
sum for the "Done" hours" (=green).

I now i have to use macros and the need to recalculate with F9 is OK.

But figuring out the macro and how to get the result put in the "sum-
cells" is the ?

Anyone?
 
R

ryguy7272

This should give you what you want:
Function CountByColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Long
'
' This function return the number of cells in InRange with
' a background color, or if OfText is True a font color,
' equal to WhatColorIndex.
'
Dim Rng As Range
Application.Volatile True

For Each Rng In InRange.Cells
If OfText = True Then
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
End If
Next Rng

End Function

It is set up for the color red right now.
Look here to find numbers/codes associated with different colors:
http://www.mvps.org/dmcritchie/excel/colors.htm


Regards,
Ryan---
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top