これでうまくいきます。
Public Sub RegressionAnalysis()
Dim sample_count As Integer
sample_count = 50
Dim r As Range
Set r = Range("A2") ' First row of data
Dim i As Integer, N As Integer, j As Integer
N = Range(r, r.End(xlDown)).Rows.Count ' Count rows
Dim rx As Range, ry As Range
i = 0: j = 0 ' data counter, output counter
Dim slope As Double, yint As Double
Do While i + 2 * sample_count < N
' Current block of data
Set rx = r.Offset(i, 0).Resize(sample_count, 1)
' Next block of data
Set ry = rx.Offset(sample_count, 0).Resize(sample_count, 1)
' Use built-in function for regression slope & intercept
slope = WorksheetFunction.slope(rx, ry)
yint = WorksheetFunction.Intercept(rx, ry)
' Output values to adjacent columns
r.Offset(j, 1).Value = slope
r.Offset(j, 2).Value = yint
' Increment the counters
i = i + sample_count
j = j + 1
Loop
End Sub
結果: