Easy Range question

wheelie pete

New Member
Joined
Mar 1, 2019
Messages
6
I'm trying to calculate the slope of 5 points in a rather large data set.

I used this bit of code:


Set xl = Range(1, 2, 3, 4, 5)
Set yl = Range(Cells(row - 5, col - 5), Cells(row, col - 5))
slopel = Application.WorksheetFunction.slope(xl, yl)

I'm trying to the set the range as just numbers, and not as cells. It doesnt like the first line.

Any ideas how to change it?

Thanks! Pete
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Maybe:
Code:
Sub pete()
Dim xl As Variant, yl As Range
xl = Array(1, 2, 3, 4, 5)
Set yl = Range("R5:R9")    ' Change range to suit. For example try R5:R9 = {10,20,30,40,50}
MsgBox "Slope = " & WorksheetFunction.Slope(yl, xl)
End Sub
 
Upvote 0
Sorry - it still doesn't work. The Slope function does not appear to like the array function.

Right now, the code looks like this:

Dim yl As Range
Dim xl As Variant

xl = Array(1, 2, 3, 4, 5)
Set yl = Range(Cells(row - 5, col - 5), Cells(row, col - 5))
slopel = Application.WorksheetFunction.slope(yl, xl)

It gives me this error - runtime error 1004 - Unable to get the slope property of the worksheet function class.

Anyideas??

Thanks! Wheelie Pete
 
Upvote 0
Can't help unless you show us what's in Range(Cells(row - 5, col - 5), Cells(row, col - 5)). Don't know how the row and col variables are defined.
 
Upvote 0
xl contains 5 elements; yl contains 6.
 
Upvote 0

Forum statistics

Threads
1,225,757
Messages
6,186,850
Members
453,379
Latest member
gabriellegonzalez

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