Hi,

I am writing the following code for a function and i get an error for the last line of the code and a message box appears with the following error..."compile error: must be first statement on the line"

what am i doing wrong?...i have highlighted the line that throws this error in red below

thanks

Function interpsigma(lowsigma As Double, highsigma As Double, lowvol As Double, highvol As Double, sigmas As Range, vols As Range, targetsigma As Double)

If targetsigma = lowsigma Then
    interpsigma = lowvol
    
ElseIf targetsigma = highsigma Then
    interpsigma = highvol
    
ElseIf targetsigma < highsigma And targetsigma > lowsigma Then
    Dim firstindexpos As Double
    Dim secondindexpos As Double
    Dim firstsigmavalue As Double
    Dim secondsigmavalue As Double
    Dim firstsigmavol As Double
    Dim secondsigmavol As Double
            
    
    firstindexpos = Application.WorksheetFunction.Match(targetsigma, sigmas, 1)
    firstsigmavalue = Application.WorksheetFunction.Lookup(targetsigma, sigmas)
        
    If firstsigmavalue = targetsigma Then
    secondindexpos = firstindexpos
    Else
    secondindexpos = firstindexpos + 1
    End If
    
    secondsigmavalue = Application.WorksheetFunction.Index(sigmas, secondindexpos)
    
    firstsigmavol = Application.WorksheetFunction.Lookup(targetsigma, sigmas, vols)
    secondsigmavol = Application.WorksheetFunction.Index(vols, secondindexpos)
    
    If firstindexpos = secondindexpos Then
    interpsigma = firstsigmavol
    Else
    interpsigma = ((targetsigma - firstsigmavalue) / (((secondsigmavalue - firstsigmavalue) * (secondsigmavol - firstsigmavol)) + firstsigmavol))
    End If
    
    
else if targetsigma > highsigma then





End Function