I don't know what the problem is then. What I'm trying to do is a
multiple regression with a rolling window. My "y" values go down column
B for about 10 years worth of data, and my "x" values cover columns D to
S also for 10 years of data. The macro works for a 1year rolling window
which means rolling the ranges D6:S266 and B6:B266 down through the 10
years of data. But when I try and do a 4year rolling window for the
ranges D6:S1047 and B6:B1047 I get a type mismatch error on line:
Range("T6").Offset(i, 0).Value = MyLinestOut(2, 1)
My full code is as follows:
Dim i
i = 0
Dim XRange As Range
Dim YRange As Range
Set XRange = Sheets("SEK").Range("D6:S1047")
Set YRange = Sheets("SEK").Range("B6:B1047")
Dim X
Dim Y
Dim MyLinestOut
Do Until i = 1561
X = XRange.Offset(i, 0).Value
Y = YRange.Offset(i, 0).Value
MyLinestOut =
Application.MMult(Application.MMult(Application.MInverse(Application.MMult(Application.Transpose(X),
X)), Application.Transpose(X)), Y)
Range("T6").Offset(i, 0).Value = MyLinestOut(2, 1)
Range("U6").Offset(i, 0).Value = MyLinestOut(3, 1)
Range("V6").Offset(i, 0).Value = MyLinestOut(4, 1)
Range("W6").Offset(i, 0).Value = MyLinestOut(5, 1)
Range("X6").Offset(i, 0).Value = MyLinestOut(6, 1)
Range("Y6").Offset(i, 0).Value = MyLinestOut(7, 1)
Range("Z6").Offset(i, 0).Value = MyLinestOut(8, 1)
Range("AA6").Offset(i, 0).Value = MyLinestOut(9, 1)
Range("AB6").Offset(i, 0).Value = MyLinestOut(10, 1)
Range("AC6").Offset(i, 0).Value = MyLinestOut(11, 1)
Range("AD6").Offset(i, 0).Value = MyLinestOut(12, 1)
Range("AE6").Offset(i, 0).Value = MyLinestOut(13, 1)
Range("AF6").Offset(i, 0).Value = MyLinestOut(14, 1)
Range("AG6").Offset(i, 0).Value = MyLinestOut(15, 1)
Range("AH6").Offset(i, 0).Value = MyLinestOut(16, 1)
Range("AI6").Offset(i, 0).Value = MyLinestOut(1, 1)
i = i + 1
Loop