More Related Content
Similar to DurbinWatsonVBA
Similar to DurbinWatsonVBA (20)
DurbinWatsonVBA
- 1. SubDurbin_Watson()
Dim UserXRange AsRange
Dim UserYRange AsRange
Dim s AsDouble
Dim j AsInteger
On Error GoTo Canceled
Set UserXRange = Application.InputBox(Prompt:="Please SelectXRange",Title:="Range XSelect",
Type:=8)
Set UserYRange = Application.InputBox(Prompt:="PleaseSelectYRange",Title:="Range YSelect",
Type:=8)
Range("J1:L5").Value =Application.WorksheetFunction.LinEst(UserYRange,UserXRange,True,True)
j = 1
s = 0
Do While Cells(j,3) <> Empty
Cells(j,4).Value=Cells(j,3).Value - (Cells(j,1).Value*Cells(1,11).Value +Cells(j,2).Value*Cells(1,
10).Value + Cells(1,12).Value)
j = j + 1
Loop
j = 2
Do While Cells(j,4) <> Empty
s = s + (Cells(j,4).Value - Cells(j - 1,4).Value) *(Cells(j,4).Value- Cells(j - 1,4).Value)
j = j + 1
Loop
v = s / Cells(5,11).Value
Columns(4).Delete
j = 1
Do While j <= 3
Columns(9).Delete
j = j + 1
Loop
MsgBox ("Durbin-WatsonStatisticis:"& v)
ExitSub