title: VBA script #VALUE
body: <p>I want to know if anyone could tell me what's wrong with the following code</p>
  <pre><code>    Function CAPACIDADEPORT(KY As Range, KX As Range, UX)
  
      Dim RQUAD As Double
      
      RQUAD = WorksheetFunction.RSq(KY, KX)
      If RQUAD &gt; 0.6 Then
          CAPACIDADEPORT = WorksheetFunction.Trend(KY, KX, UX)
          
      Else:
          CAPACIDADEPORT = WorksheetFunction.Average(ActiveCell.Offset(-5))
      End If
          
     End Function
  </code></pre>
  <p>My goal is to create a function that return me the avarage of the last rows if the rquad value is lesser than 0.6 and the trend if the rqud is bigger or equal 0.6. But when I aplly the code it return to me a #VALUE, being that besides the UX parameters that is in general format, the other two are a range of numeric cells.</p>