PKennedyG77
New Member
- Joined
- Jan 2, 2016
- Messages
- 22
- Office Version
- 365
- Platform
- 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
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: