Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with slope function

Status
Not open for further replies.

rbuesseler

Technical User
May 8, 2013
2
US
I don't know why my fuction won't work.

I have several datasets that I need to calculate the slope of the line. They are of varrying length, but are of known length.

x: Column 10, of length "sumloop1" (sumloop1 was previously used as a counter to count how long the column is)
y: Column 11, of length "sumloop1"

Set x1slope45 = Range(Cells(3, 10), Cells(sumloop1, 10))
Set y1slope45 = Range(Cells(3, 11), Cells(sumloop1, 11))
slope45 = Application.WorksheetFunction.Slope(y1slope45, x1slope45)
Cells(1,10) = slope45

I get an error that says: "Unable to get the Slope property of the WorksheetFunction class"

I'm a relative newbie to VBA, so I am sorry if this seems very basic.

Thank you for the timely assistance.
 
I would suspect it's because SLOPE() wants to be fed a number and you are trying to feed it a RANGE.

But you have the coordinates of two points. Why not just calculate the slope directly rather than use the function?
 
Slope accepts ranges. Check their size - this error occurs for single cells input (sumloop1=3).
Your code works with active worksheet, you may consider to create more stable references (pseudocode: YourWorksheet.Cells(..,..)).

combo
 
Yes, that is what my problem was. I mixed up my variables. I should have been using my variable "countloop1" rather than "sumloop1". "sumloop1" actually has a value of 1.2416 - which obviously would not work for the slope function to call a reference to cell 1.2416!

Thank you for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top