use linest results without referring to cells

ThomasOES

Board Regular
Joined
Aug 29, 2017
Messages
174
Hello
Currently I use linest to generate a slope and constant.
The range represents two adjacent cells.
VBA Code:
Range(fdeg, cnst) = Application.LinEst(DriftDat, DriftIn)
I would like to use the 1st degree coefficient and constant without the need for cells.
Something like
VBA Code:
fdeg, cnst = Application.LinEst(DriftDat, DriftIn)
with fdeg being the 1st degree coefficient and cnst being the constant
Any ideas?
Thanks
Tom
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Got it

VBA Code:
Set yns = Range("L2:L5")
Set xns = Range("M2:M5")

fdeg = Application.Index(Application.LinEst(xns, yns), 1)
cnst = Application.Index(Application.LinEst(xns, yns), 2)
 
Upvote 0
or

LE = Application.LinEst(DriftDat, DriftIn)
fdeg = LE(1)
cnst = LE(2)
 
Upvote 0
Dim fdeg As Double, cnst As Double
fdeg = WorksheetFunction.Slope(DriftDat, DriftIn)
cnst = WorksheetFunction.Intercept(DriftDat, DriftIn)
 
Upvote 0
Slick code JGordon. I adapted it to a 3rd degree polynomial.

VBA Code:
Set yns = Range("L2:L5")
Set xns = Range("M2:M5")

fird = Application.LinEst(xns, yns)
firco = fird(1)
cnst = fird(2)

thid = Application _
        .LinEst(xns, _
            Application.Power(yns, Array(1, 2, 3)))
thid3 = thid(1)
thid2 = thid(2)
thid1 = thid(3)
thidc = thid(4)

Thanks

Tom
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,443
Members
448,898
Latest member
drewmorgan128

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