Run-time error 9 subscript out of range

cwallace70

Board Regular
Joined
Mar 7, 2011
Messages
172
I am running a VBA and getting the run time error when it reaches Windows (Filename0) .Activate
I m new to VBA and I can't seem to figure this out. Please help
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Firstly make sure Filename0 is an actual file.
Also, it would help if you posted your code.
 
Upvote 0
Here is my code

Range("M21").Select

Workbooks.Open Path & Filename1
' Workbooks.Open fileName:="S:\Stat Reporting\Workpapers\2022\4Q22\MT Wings Support\LAH-4Q22-GLICOA-NAIC.xlsx"
Range("C2:D2").Select
Selection.Copy
' Windows("FLASH MACROS.xlsm").Activate
' Windows("4Q22 Master Template.xlsm").Activate
Windows(Filename0).Activate
Sheets("INPUT").Select
Range("A55").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("A56").Select
 
Upvote 0
Here is my code

Range("M21").Select

Workbooks.Open Path & Filename1
' Workbooks.Open fileName:="S:\Stat Reporting\Workpapers\2022\4Q22\MT Wings Support\LAH-4Q22-GLICOA-NAIC.xlsx"
Range("C2:D2").Select
Selection.Copy
' Windows("FLASH MACROS.xlsm").Activate
' Windows("4Q22 Master Template.xlsm").Activate
Windows(Filename0).Activate
Sheets("INPUT").Select
Range("A55").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("A56").Select
 
Upvote 0
Attribute VB_Name = "Module35"
Sub Button47_Click()
Attribute Button47_Click.VB_ProcData.VB_Invoke_Func = " \n14"
'
' Button47_Click Macro
'

Dim Path As String
Dim Filename0 As String
Dim Filename1 As String
Dim Filename2 As String
Dim Filename3 As String
Dim Filename4 As String
Dim Filename5 As String
Dim Filename6 As String


Sheets("INPUT").Select
Filename0 = Range("F77").Value
Filename1 = Range("D62").Value
Filename2 = Range("D63").Value
Filename3 = Range("D64").Value
Filename4 = Range("D65").Value
Filename5 = Range("D66").Value
Filename6 = Range("D67").Value


Path = Worksheets("Input").Range("A70").Value
' Filename6 = Range("B36").Value
Workbooks.Open Path & Filename1
Workbooks.Open Path & Filename2
Workbooks.Open Path & Filename3
Workbooks.Open Path & Filename4
Workbooks.Open Path & Filename5
Workbooks.Open Path & Filename6


'
Range("M21").Select

Workbooks.Open Path & Filename1
' Workbooks.Open fileName:="S:\Stat Reporting\Workpapers\2022\4Q22\MT Wings Support\LAH-4Q22-GLICOA-NAIC.xlsx"
Range("C2:D2").Select
Selection.Copy
' Windows("FLASH MACROS.xlsm").Activate
' Windows("4Q22 Master Template.xlsm").Activate
Windows(Filename0).Activate
Sheets("INPUT").Select
Range("A55").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("A56").Select

Workbooks.Open Path & Filename2
' Workbooks.Open fileName:="S:\Stat Reporting\Workpapers\2022\4Q22\MT Wings Support\LAH-4Q22-GIAC-NAIC.xlsx"
Range("C2:D2").Select
application.CutCopyMode = False
Selection.Copy
' Windows("FLASH MACROS.xlsm").Activate
' Windows("4Q22 Master Template.xlsm").Activate
Windows(Filename0).Activate
Sheets("INPUT").Select
Range("A56").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("A57").Select

Workbooks.Open Path & Filename3
' Workbooks.Open fileName:="S:\Stat Reporting\Workpapers\2022\4Q22\MT Wings Support\LAH-4Q22-BLICOA-NAIC.xlsx"
Range("C2:D2").Select
application.CutCopyMode = False
Selection.Copy
' Windows("FLASH MACROS.xlsm").Activate
' Windows("4Q22 Master Template.xlsm").Activate
Windows(Filename0).Activate
Sheets("INPUT").Select
Range("A57").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("A58").Select

Workbooks.Open Path & Filename4
' Workbooks.Open fileName:="S:\Stat Reporting\Workpapers\2022\4Q22\MT Wings Support\LAH-4Q22-PALIC-NAIC.xlsx"
Range("C2:D2").Select
application.CutCopyMode = False
Selection.Copy
' Windows("FLASH MACROS.xlsm").Activate
' Windows("4Q22 Master Template.xlsm").Activate
Windows(Filename0).Activate
Sheets("INPUT").Select
Range("A58").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("A59").Select

Workbooks.Open Path & Filename5
' Workbooks.Open fileName:="S:\Stat Reporting\Workpapers\2022\4Q22\MT Wings Support\LAH-4Q22-FSLIC-NAIC.xlsx"
Range("C2:D2").Select
application.CutCopyMode = False
Selection.Copy
' Windows("FLASH MACROS.xlsm").Activate
' Windows("4Q22 Master Template.xlsm").Activate
Windows(Filename0).Activate
Sheets("INPUT").Select
Range("A59").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("A60").Select

Workbooks.Open Path & Filename6
' Workbooks.Open fileName:="S:\Stat Reporting\Workpapers\2022\4Q22\MT Wings Support\LAH-4Q22-SALIC-NAIC.xlsx"
Range("C2:D2").Select
application.CutCopyMode = False
Selection.Copy
' Windows("FLASH MACROS.xlsm").Activate
' Windows("4Q22 Master Template.xlsm").Activate
Windows(Filename0).Activate
Sheets("INPUT").Select
Range("A60").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("A61").Select


' Windows("4Q22 Master Template.xlsm").Activate
Windows(Filename0).Activate
Sheets("Annual Exhibits - Flash").Select
Range("C31:AG36").Select
Selection.Copy
Range("C5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("C13").Select

Range("C63:I227").Select
Selection.Copy
Range("M63").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("C13").Select

Range("K42:M47").Select
Selection.Copy
Range("K15").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("C13").Select

Sheets("INPUT").Select
Range("A79").Select

Windows(Filename1).Activate
ActiveWorkbook.Close
Windows(Filename2).Activate
ActiveWorkbook.Close
Windows(Filename3).Activate
ActiveWorkbook.Close
Windows(Filename4).Activate
ActiveWorkbook.Close
Windows(Filename5).Activate
ActiveWorkbook.Close
Windows(Filename6).Activate
ActiveWorkbook.Close



' Windows("BLICOA LAH-2022-A-NAIC-20221214144407_Mult_0.xlsx").Activate
' ActiveWorkbook.Close







End Sub
 
Upvote 0
In the code you posted, I don't see a variable named
VBA Code:
Filename0
 
Upvote 0
Do you get the same results with
VBA Code:
Workbooks(Filename0).Activate
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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