Hi, everyone, My english name is Jack, I am from Shanghai, China. I am an analyst. Now I meet a VBA problem. I searched online and got many methods but no one can solve the problem. MrExcel is famous and I hope I can get help here.When I use my code to do regression, it always shows "error 1004". (notes: I loaded VBA tool pak, and ticked "ATPVBAEN.XLA" in "reference" under "tools" in VBE)
My code is as follows:
///////starts
Dim i, j As Integer
Cells(2, 2).Select
i = Selection.End(xlDown).Row
j = Selection.End(xlToRight).Column
Application.Run "ATPVBAEN.XLA!Regress", ActiveSheet.Range(Cells(2, 2), Cells(i, 2)), ActiveSheet.Range(Cells(2, 3), Cells(i, j)), False, False, , ActiveSheet.Range("$H$26"), False, False, False, False, , False
//////ends
The 3 solutions I found by google are as follows:
1. If Application.Version <= 11 Then
Application.Run "ATPVBAEN.XLA!Regress" (omit...)
ElseIf Application.Version > 11 Then
Application.Run "ATPVBAEN.XLAM!Regress",(Omit...)
end if
but it doesn't work
2. Microsoft website gave a method: replace (Application.Run "ATPVBAEN.XLA!Regress") with (Application.Run "'Analysis Toolpak - VBA'!Regress) or (Regression), it can't help either; from http://support.microsoft.com/kb/192642
3. add code: Application.Workbooks.Open "C:\Program Files\Microsoft Office\OFFICE11\Library\Analysis\atpvbaen.xla" (it's already my laptop path), but can't work.
Hope you can help me! Thank you very much!
My code is as follows:
///////starts
Dim i, j As Integer
Cells(2, 2).Select
i = Selection.End(xlDown).Row
j = Selection.End(xlToRight).Column
Application.Run "ATPVBAEN.XLA!Regress", ActiveSheet.Range(Cells(2, 2), Cells(i, 2)), ActiveSheet.Range(Cells(2, 3), Cells(i, j)), False, False, , ActiveSheet.Range("$H$26"), False, False, False, False, , False
//////ends
The 3 solutions I found by google are as follows:
1. If Application.Version <= 11 Then
Application.Run "ATPVBAEN.XLA!Regress" (omit...)
ElseIf Application.Version > 11 Then
Application.Run "ATPVBAEN.XLAM!Regress",(Omit...)
end if
but it doesn't work
2. Microsoft website gave a method: replace (Application.Run "ATPVBAEN.XLA!Regress") with (Application.Run "'Analysis Toolpak - VBA'!Regress) or (Regression), it can't help either; from http://support.microsoft.com/kb/192642
3. add code: Application.Workbooks.Open "C:\Program Files\Microsoft Office\OFFICE11\Library\Analysis\atpvbaen.xla" (it's already my laptop path), but can't work.
Hope you can help me! Thank you very much!