It's hard to visualize someone else's spreadsheet layout, but if you're going to use custom functions then the sky is the limit - just modify what you have to check the reference date in addition to the backcolor.
Using named ranges:
=CountColor(GreenCell, ColorRange, DateCell)
=CountColor(YellowCell, ColorRange, DateCell)
=CountColor(RedCell, ColorRange, DateCell)
Using cell references:
=CountColor(G1, A1:A40, H1) ... or whatever cell ranges you're using.
I modified your function to check the cell to the right of the colored cell (which I'm calling the imported date) to see if it is greater than the reference date cell (rRefDate). You could add another argument specifying the number of columns to offset if you plan on calling this function from different sheets.
Function CountColor(rColor As Range, rSumRange As Range, rRefDate As Range) As Integer
Dim rCell As Range
Dim iCol As Integer
Dim intResult As Integer
iCol = rColor.Interior.ColorIndex
For Each rCell In rSumRange
If rCell.Interior.ColorIndex = iCol Then
If rCell.Offset(0, 1) > rRefDate Then
intResult = intResult + 1
End If
End If
Next rCell
CountColor = intResult
End Function
You can also use a database function to get the same results. The DCOUNT(database, field, criteria) function will work if it's set up right. Say you have:
ColA ColB
---------------------
Colors Dates
---------------------
1 1/1/02
---------------------
2 5/3/02
---------------------
1 8/12/02
---------------------
3 9/3/01
---------------------
You can name that range 'database' (A1:A5 - needs to include the headings).
Then you define your criteria ranges like this (headings included also):
ColR ColS
---------------------
Dates Colors
--------------------- Range = R1:R2
>4/1/02 1
---------------------
Dates Colors
--------------------- Range = R3:R4
>4/1/02 2
---------------------
Dates Colors
--------------------- Range = R5:R6
>4/1/02 3
---------------------
Then to get the totals for each color whose date meets the criteria (>4/1/02), use the DCOUNT():
TotalGreens =DCOUNT(database, "Colors", R1:R2) = 1
TotalYellows =DCOUNT(database, "Colors", R3:R4) = 1
TotalReds = DCOUNT(database, "Colors", R5:R6) = 0
You can set up the colors column with conditional formatting so that is has 3 conditions:
If value = 1, the backcolor and text color is green
If value = 2, the backcolor and text color is yellow
If value = 3, the backcolor and text color is red
That way all you see is the color, and you can still use the numeric value in your formulas.
Am I in the ball park yet?
VBSlammer