Slope formula using dates

Reset

Board Regular
Joined
Apr 16, 2010
Messages
227
I have rows where the alternating cells are daters and values. I want to use the Slope formula but it wants the arguments as variable type double. It recognizes dates in Excel but not VBA. Can I make this work?
Code:
Sub t()
For x = 2 To Application.WorksheetFunction.CountA(Columns(1))
    c = Application.WorksheetFunction.CountA(Rows(x))
    ReDim d((c - 1) / 2) As Date
    ReDim v((c - 1) / 2) As Double
    For y = 2 To c Step 2
        d(y / 2) = Cells(x, y)
        v((y / 2) + 1) = Cells(x, y + 1)
    Next y
    s = Application.WorksheetFunction.Slope(d, v)
    Cells(x, y + 1) = s
Next x
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Maybe just change array d to Double.
 
Last edited:
Upvote 0
Ok, the function seems to work outside the code if I arrange the data manually. Because the rows alternate between dates and values and each row is a unique size I need to put the data in arrays. How do I call the complete d and v arrays in the function?
Code:
s = Application.WorksheetFunction.Slope(d, v)
Doesn't cut it as valid arguments.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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