R
Ron
If I have certain numbers in a column, in red text, can I sum or count only
those cells?
Thanks,
Ron
those cells?
Thanks,
Ron
If I have certain numbers in a column, in red text, can I sum or count only
those cells?
Thanks,
Ron
Laroche J said:Ron wrote on 2009-04-13 18:26:
There's no real built-in way. If you have Excel v.X or Excel 2004, you could
build custom functions.
Function CountIfColor(MyRange As Range, MyColor As Integer)
CountIfColor = 0
For Each c In MyRange.Cells
If c.Font.ColorIndex = MyColor Then
CountIfColor = CountIfColor + 1
End If
Next
End Function
Function SumIfColor(MyRange As Range, MyColor As Integer, SumRange As Range)
SumIfColor = 0
RangeOffset = SumRange.Row - MyRange.Row
For Each c In MyRange.Cells
If c.Font.ColorIndex = MyColor Then
SumIfColor = SumIfColor + SumRange.Parent.Cells(c.Row + _
RangeOffset, SumRange.Column).Value
End If
Next
End Function
Use as you would COUNTIF and SUMIF, except that the second argument is the
color index you're looking for. The brightest shade of red has value 3. This
function could help find the color index of a target cell:
Function FontColor(MyRange As Range)
FontColor = MyRange.Font.ColorIndex
End Function
Put these functions in one of the workbook's modules.
JL
Mac OS X 10.4.11
Office v.X 10.1.9, Office 2008 trial
Ok, FontColor and CountIfColor work fine.
SumIfColor returns a #Value error on the same cells. Triple checked typing.
Also, if I write this in Personal.xls, won't it be available to all
workbooks I open, as long as Personal is open?
Thanks,
Ron
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.