Jase
Jase

Reputation: 1105

Compile Error: Sub or Function not defined - Excel Function definition

I'm trying to define the following function but am getting Compile Error: Sub or Function not defined. The debugged is highlighting the first line. Any ideas as to what could be incorrect here?

Function MAXELSEMIN(A As Integer, B As Double, C As Double) As Double
If A = 1 Then
    test = Max(B, C)
ElseIf A = -1 Then
    test = Min(B, C)
Else
    test = 0
End If
End Function

Upvotes: 0

Views: 76

Answers (1)

BigBen
BigBen

Reputation: 50008

Use the WorksheetFunction object to call the functions in question:

test = WorksheetFunction.Max(B, C)

test = WorksheetFunction.Min(B, C)

and then at the end add the line:

MAXELSEMIN = test

Upvotes: 1

Related Questions