Getting error "Runtime error '9' Subscript out of range"

jig

New Member
Joined
Mar 20, 2009
Messages
2
Hi,
When I give print command, i am getting "Runtime error '9' Subscript out of range". I use Excel 2007 and Windows XP is the operating system. I am copying the code below. Please help,
Thank you

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim WS As Worksheet
Dim MainMenu As Worksheet
Dim Login As Worksheet
Dim Center As String
Dim Right As String
Dim SheetName(3) As String
SheetName(1) = "Sheeting"
SheetName(2) = "RPM"
SheetName(3) = "Delineator"
Set MainMenu = Sheets("Main Menu")
Set Login = Sheets("Login")
Center = "Installation Date: " & MainMenu.Cells(10, 10) & vbCr _
& "Test Date: " & MainMenu.Cells(8, 10) & vbCr _
& "Age: " & MainMenu.Cells(9, 4) & vbCr _
& "Tested By: " & MainMenu.Cells(9, 10) & vbCr _
& "Tested as per the requirements of :" & MainMenu.Cells(13, 4) & vbCr _
& "Comments :" & MainMenu.Cells(15, 4)
Right = "Material ID: " & MainMenu.Cells(12, 4) & vbCr _
& "Application Type: " & MainMenu.Cells(12, 10) & vbCr _
& "Reported By: " & MainMenu.Cells(9, 10) & vbCr _
& "Report Period: " & MainMenu.Cells(13, 10)
For i = 1 To 3
Set WS = Sheets(SheetName(i))
WS.PageSetup.CenterHeader = Center
WS.PageSetup.RightHeader = Right
Next i
End Sub
Private Sub Workbook_Open()
Create_Main_Toolbar
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi jig, welcome to the board.

I'm not an expert on macros, but if you want help with this type of thing, it will help if you specify which line of the macro is causing the problem. It will be highlighted when you try and run it.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

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