Runtime Error 9

PKennedyG77

New Member
Joined
Jan 2, 2016
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hi guys. This is a strange one.

A colleague of mine keeps getting a runtime error 9 whenever he tries to run a vba code.

The code opens up a second workbook and looks to activate the relevant workbook when appropriate.

The code is

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif] Sub NormalWeek62()
TheFirst = 0
FirstRow = 0
LastRow = 0[/FONT]

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Workbooks("Atlas62 " & TheYear & "").Activate
Sheets("" & WeekIdentifier & "" & TheWeek & "").Activate
Range("CH2").Select 'Goes to top of data ranges
Yesterday = WeekdayName(TodayNumber - 1, False, vbSunday) 'takes 1 from current day to get yesterday[/FONT]


It crashes with the runtime error 9 on the 4th Line (highlighted red). TheYear and WeekIdentifier variables are taken from another Public macro. It is showing the correct value when I hover the cursor over it.
Strange thing is, it works perfectly fine on my laptop.

It just does not want to activate the other workbook.

I'm confused. Could it be one of the Excel settings?

Thanks
Pat Kennedy
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
missing what. Rank amateur here.

If you mean that the workbook is not there, it is and the year is also there.
 
Upvote 0
Try adding the file extension to the workbook name.
 
Upvote 0
Thanks, will give that a go but why does it work ok on my laptop and not his?
Will be two weeks before he is back and I can try this
 
Upvote 0
It's down to the system settings.
I suspect that you have "Hide known file extensions" checked, whilst your colleague doesn't.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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