Run-Time error '9', but why

e17nel

New Member
Joined
Aug 9, 2010
Messages
17
I have the below code that I am trying to run. I am compiling data for all employees on my team for 2010. Some people didn't join the team until part way through the year and some people left before the year was over. What I want my code to do is look through the open workbooks, find the first sequential month that is open, run my other macro, close the workbook without saving and then move on to the next month. The workbooks I have open are August through December. When I run the macro, it sees that I don't have January open so it skips to February but then errors out on the highlighted line instead of skipping to March. Does anyone know why and either how to fix this or make it better? The workbook names are the same as in the macro so it's not a filename issue. Thanks in advance!

Sub Macro5()
'
' Macro5 Macro
'
' Keyboard Shortcut: Ctrl+i
'
On Error GoTo Feb:
Windows("January Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("January Tracker.xlsx").Close False

Feb:
On Error GoTo Mar:
Windows("February Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("February Tracker.xlsx").Close False

Mar:
On Error GoTo Apr:
Windows("March Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("March Tracker.xlsx").Close False

Apr:
On Error GoTo May:
Windows("April Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("April Tracker.xlsx").Close False

May:
On Error GoTo Jun:
Windows("May Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("May Tracker.xlsx").Close False

Jun:
On Error GoTo Jul:
Windows("June Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("June Tracker.xlsx").Close False

Jul:
On Error GoTo Aug:
Windows("July Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("July Tracker.xlsx").Close False

Aug:
On Error GoTo Sep:
Windows("August Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("August Tracker.xlsx").Close False

Sep:
On Error GoTo Oct:
Windows("September Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("September Tracker.xlsx").Close False

Oct:
On Error GoTo Nov:
Windows("October Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("October Tracker.xlsx").Close False

Nov:
Windows("November Tracker.xlsx").Activate
On Error GoTo Dec:
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("November Tracker.xlsx").Close False

Dec:
On Error GoTo LastErr:
Windows("December Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("December Tracker.xlsx").Close False

LastErr:
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I haven't ploughed through all that code but runtime error 9 means that excel cannot find a specified sheet or workbook, it may be that you have a typo in one of the names in your code or on the actual sheet tab, it may be a leading or trailing space, double check your code and names very carefully.
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,947
Members
449,198
Latest member
MhammadishaqKhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top