-1
Hello I have the following vba code which is a function that takes three parameters and calculates the functions Bult-in trend and rquad and depending on the result it returns trend or the average of the last values.
Function CAPACIDADEPORT(KY As Range, KX As Range, UX)
Dim RQUAD As Double
Dim TENDE As Variant
RQUAD = Application.WorksheetFunction.RSq(KY.Value, KX.Value)
TENDE = Application.WorksheetFunction.Trend(KY.Value, KX.Value, UX.Value)
If RQUAD > 0.6 Then
CAPACIDADEPORT = TENDE
Else:
CAPACIDADEPORT = Application.WorksheetFunction.Average(KY.Cells(KY.Cells.Count).Offset(-4).Resize(5))
End If
End Function
This function above works normally. The problem is when I add one more test in if(TENDE > 0), after I change it always returns value error being that the data I pass as parameter for both are the same.
Function CAPACIDADEPORT(KY As Range, KX As Range, UX)
Dim RQUAD As Double
Dim TENDE As Variant
RQUAD = Application.WorksheetFunction.RSq(KY.Value, KX.Value)
TENDE = Application.WorksheetFunction.Trend(KY.Value, KX.Value, UX.Value)
If RQUAD > 0.6 AND TENDE > 0 Then
CAPACIDADEPORT = TENDE
Else:
CAPACIDADEPORT = Application.WorksheetFunction.Average(KY.Cells(KY.Cells.Count).Offset(-4).Resize(5))
End If
End Function
I wonder what could be leading to that mistake. Grateful from now on.
How are you calling the function in the spreadsheet, including the 3 arguments? I noticed that the last parameter you did not mark as
As Range
, what’s going to him?– Eduardo Bissi
In the last parameter there is only one cell with a number. I call the function like this: =capacidadeport(B2:B15;A2:A15;A16)
– fafernandes