G
Guest
Guest
I recorded a macro in a workbook that will open another book, filter column E of that sheet for the number "1", select and copy those active rows and paste them into book1 and then close book2.
It works fine when I run it as a macro alone, but when I pasted the exact macro into my "workbook_open() macro in "This Worksheet", I get a runtime error 9 "subscript out of range" error.
The debugger highlights the 4th line from the bottom of my macro:
Windows("Data.xls").Activate.
Can someone please tell me how to fix this?
Thanks in advance!
Mav
Here is the macro:
Cells.Select
Selection.ClearContents
Range("A1").Select
Workbooks.Open Filename:="C:routesData.xls"
Columns("E:E").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="=1", Operator:=xlAnd
Range("A2").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Windows("Route 1.xls").Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=False
Range("A1").Select
Windows("Data.xls").Activate
Application.CutCopyMode = False
Range("A1").Select
ActiveWindow.Close
End Sub
It works fine when I run it as a macro alone, but when I pasted the exact macro into my "workbook_open() macro in "This Worksheet", I get a runtime error 9 "subscript out of range" error.
The debugger highlights the 4th line from the bottom of my macro:
Windows("Data.xls").Activate.
Can someone please tell me how to fix this?
Thanks in advance!
Mav
Here is the macro:
Cells.Select
Selection.ClearContents
Range("A1").Select
Workbooks.Open Filename:="C:routesData.xls"
Columns("E:E").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="=1", Operator:=xlAnd
Range("A2").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Windows("Route 1.xls").Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=False
Range("A1").Select
Windows("Data.xls").Activate
Application.CutCopyMode = False
Range("A1").Select
ActiveWindow.Close
End Sub