I have this Function I found at Chip Pearson's site for SumIfByColor.
how would one modify it to be a MaxIfByColor or MinIfByColor?
I thought it would be as easy as replacing sum with min/max but i was mistaken.
here is the code:
thanks
quincy
how would one modify it to be a MaxIfByColor or MinIfByColor?
I thought it would be as easy as replacing sum with min/max but i was mistaken.
here is the code:
Code:
Function SumIfByColor(InRange As Range, _
WhatColorIndex As Integer, SumRange As Range, _
Optional OfText As Boolean = False) As Variant
'
' This function will return the SUM of the values of cells in
' SumRange where the corresponding cell in InRange has a background
' color (or font color, if OfText is true) equal to WhatColorIndex.
'
Dim OK As Boolean
Dim Ndx As Long
Application.Volatile True
If (InRange.Rows.Count <> SumRange.Rows.Count) Or _
(InRange.Columns.Count <> SumRange.Columns.Count) Then
SumIfByColor = CVErr(xlErrRef)
Exit Function
End If
For Ndx = 1 To InRange.Cells.Count
If OfText = True Then
OK = (InRange.Cells(Ndx).Font.ColorIndex = WhatColorIndex)
Else
OK = (InRange.Cells(Ndx).Interior.ColorIndex = WhatColorIndex)
End If
If OK And IsNumeric(SumRange.Cells(Ndx).Value) Then
SumIfByColor = SumIfByColor + SumRange.Cells(Ndx).Value
End If
Next Ndx
End Function
thanks
quincy