[VBA] Passing an integer to the TREND() function

tropicbliss

New Member
Joined
Oct 30, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I am making a function that requires the use of the TREND() function in Excel. However when I pass an Integer to the third parameter of the function, a #VALUE! error occurs.
I know that the TREND() function accepts the Variant data type. I tried casting the Integer into a Variant using CVar() but it does not work.
Does anybody know how do I fix this issue?

Excel Formula:
Function TEST()
    Dim aY(1 To 2) As Double
    Dim aX(1 To 2) As Double

    aY(1) = 4000: aY(2) = 20000
    aX(1) = 0.3: aX(2) = 0.32

    TEST = Application.Trend(aY, aX, 5)(1)
End Function
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hello there,

What about:

VBA Code:
Function TEST()
    Dim aY(1 To 2) As Double
    Dim aX(1 To 2) As Double
    Dim bX(1 To 1) As Double

    aY(1) = 4000: aY(2) = 20000
    aX(1) = 0.3: aX(2) = 0.32
    bX(1) = 5

    TEST = Application.Trend(aY, aX, bX)
End Function
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,392
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top