ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   A hopefully simple question about SLOPE()... (https://www.excelbanter.com/excel-programming/293262-hopefully-simple-question-about-slope.html)

dcarter

A hopefully simple question about SLOPE()...
 
Howdy
I have two columns of data (X and Y values, a simple line) that I need to find the slope and y-intercept of with VBA. I've read about WorksheetFunction.Slope() and .Intercept as well as Index(LinEst()1), but my problem stems from my two datasets existing in array form. I retrieve the data from columns on a sheet, but perform several normalizing functions on the arrays before needing slope and intercept
The worksheet functions talk about accepting arrays as data, and you can pass the functions worksheet arrays {1;2;3;...}, but nothing doing in VBA. I've tried leaving the arrays two dimentional as well as converting them to one dimention per set. Any ideas, or am I going to have to pass the arrays back to a range and pass that to the function

Much appreciated
-Dustin Carter

Tom Ogilvy

A hopefully simple question about SLOPE()...
 
varrX = Array(1,2,3,4,5)
varrY = Array(5,7,3,6,8)
? worksheetFunction.Slope(varry,varrx)
0.5
? worksheetFunction.Intercept(varry,varrx)
4.3

works fine for me.

--
Regards,
Tom Ogilvy


"dcarter" wrote in message
...
Howdy,
I have two columns of data (X and Y values, a simple line) that I need

to find the slope and y-intercept of with VBA. I've read about
WorksheetFunction.Slope() and .Intercept as well as Index(LinEst()1), but my
problem stems from my two datasets existing in array form. I retrieve the
data from columns on a sheet, but perform several normalizing functions on
the arrays before needing slope and intercept.
The worksheet functions talk about accepting arrays as data, and you can

pass the functions worksheet arrays {1;2;3;...}, but nothing doing in VBA.
I've tried leaving the arrays two dimentional as well as converting them to
one dimention per set. Any ideas, or am I going to have to pass the arrays
back to a range and pass that to the function?

Much appreciated,
-Dustin Carter





All times are GMT +1. The time now is 07:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com