N
na gCopaleen
I have a timetable in Excel.
People put in their holidays by filling a cell with the colour red for
times when they will be off.
I'd like to be able to add up (CountIf ?) all the red cells in a row
and get the number of days that the person is off.
I've tried:
---------------------------
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.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng
End Function
--------------------
But when I call it via
=countbycolor(D11:H11,4, FALSE)
I get nothing but #NAME
Anyone help
People put in their holidays by filling a cell with the colour red for
times when they will be off.
I'd like to be able to add up (CountIf ?) all the red cells in a row
and get the number of days that the person is off.
I've tried:
---------------------------
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.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng
End Function
--------------------
But when I call it via
=countbycolor(D11:H11,4, FALSE)
I get nothing but #NAME
Anyone help