LinEst in Vba - not using Excel ranges

Sherlock

New Member
Joined
Nov 12, 2008
Messages
8
Hi, I am calculating variables in Vba and want to find their co=effiicients in the for y=a +bx +cx^2. This works great if I output my variables to excel and then pick up this range however as I am generating the variables in vba and have an array of variables I would rather not have to keep spitting them out to excel then picking them up again. The three important lines in my code are:

c(nFix - j) = WorksheetFunction.Index(WorksheetFunction.LinEst(inpv, Application.Power(inps, Array(1, 2))), 1)

b(nFix - j) = WorksheetFunction.Index(WorksheetFunction.LinEst(Range(Vc), Application.Power(Range(SPd), Array(1, 2))), 1, 2)

a(nFix - j) = WorksheetFunction.Index(WorksheetFunction.LinEst(Range(Vc), Application.Power(Range(SPd), Array(1, 2))), 1, 3)

As you can see for c I am referring to inpv and inps these are arrays. I have tried using inpv(), etc but no luck

b and a work great, here I am reffering to ranges Vc and SPd. As I am going through this a lot of times it seems rather inelegant not to be able to do the whole thing in vba - i would rather not use the dump to spreadsheet then pick up again approach!

Thanks for your help!!
 
Are you still getting the same error? This worked for me:
Code:
   Dim arr1(1 To 5), arr2(1 To 5)
   Dim varDataP, varDataL, dataout
   arr1(1) = 0.571795
   arr1(2) = 1.232948
   arr1(3) = 1.127119
   arr1(4) = 0.426315
   arr1(5) = 0
   arr2(1) = 1.618501
   arr2(2) = 0.66472
   arr2(3) = 1.43194
   arr2(4) = 1.694461
   arr2(5) = 1.935061
   varDataP = Application.Power(Application.Transpose(arr2), Array(1, 2))
   varDataL = WorksheetFunction.Index(Application.WorksheetFunction.LinEst(arr1, Application.Transpose(varDataP)), 1)
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Copying and pasting your code into a new sub works fine so I'm thinking there must be something odd going on with the dimensioning of my arrays. I'll have a further look through.

Thanks v much for your help!
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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