[vba]
Public Function MAXIF(rng1, op, cond, Optional rng2)
Dim sFormula As String
If IsMissing(rng2) Then
Set rng2 = rng1
End If
If TypeName(cond) = "Range" Then
If Not IsNumeric(cond.Value) Then
sFormula = """" & cond & ""","
Else
sFormula = "" & cond & ","
End If
ElseIf TypeName(cond) = "String" Then
sFormula = """" & cond & ""","
Else
sFormula = "" & cond & ","
End If
sFormula = "MAX(IF(" & rng1.Address & op & sFormula & rng2.Address & "))"
MAXIF = rng1.Parent.Evaluate(sFormula)
End Function
[/vba]