Runtime Error '9' Subscript out of range

TylerV

New Member
Joined
Aug 24, 2013
Messages
16
I'm receiving a Runtime Error '9' Subscript out of range when I try to run run the below code.

I've tried changed the
Code:
Range("A5").Select
but that didn’t help.

The code below was created using the macro recorder.
This is the part that is highlighted when debugging
Code:
Windows( _
        "Fulfillment_Weekly_Headcount" _
        ).Activate
Code:
 Sub Macro1()
    Range("E6:G6,E11:G26").Select
    Range("E11").Activate
    ActiveWindow.SmallScroll Down:=21
    Range("E6:G6,E11:G26,E31:G38").Select
    Range("E31").Activate
    ActiveWindow.SmallScroll Down:=6
    Range("E6:G6,E11:G26,E31:G38,E43:G43,E48:G48,E53:G53").Select
    Range("E53").Activate
    ActiveWindow.SmallScroll Down:=21
    Selection.ClearContents
    ActiveWindow.SmallScroll Down:=-66
    Range("E13").Select
    Sheets("CR Sum").Select
    Range("A5").Select
    Workbooks.Open Filename:="c:\Reports\repory1__DB_Summary.csv"
    Range("A2").Select
    ActiveWindow.ScrollRow = 4
    ActiveWindow.ScrollRow = 5
    ActiveWindow.ScrollRow = 7
    ActiveWindow.ScrollRow = 8
    ActiveWindow.ScrollRow = 10
    ActiveWindow.ScrollRow = 12
    ActiveWindow.ScrollRow = 15
    ActiveWindow.ScrollRow = 17
    ActiveWindow.ScrollRow = 21
    ActiveWindow.ScrollRow = 25
    ActiveWindow.ScrollRow = 28
    ActiveWindow.ScrollRow = 32
    ActiveWindow.ScrollRow = 35
    ActiveWindow.ScrollRow = 38
    ActiveWindow.ScrollRow = 40
    ActiveWindow.ScrollRow = 43
    ActiveWindow.ScrollRow = 45
    ActiveWindow.ScrollRow = 47
    ActiveWindow.ScrollRow = 48
    ActiveWindow.ScrollRow = 49
    ActiveWindow.ScrollRow = 51
    ActiveWindow.ScrollRow = 52
    ActiveWindow.ScrollRow = 53
    Range("A2:K1044").Select
    Selection.Copy
    Windows( _
        "Fulfillment_Weekly_Headcount" _
        ).Activate
    ActiveSheet.Paste
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi, TylerV,

add the file extension to the command, I assumed it to be xlsx:
Code:
Windows( _
        "Fulfillment_Weekly_Headcount.xlsx" _
        ).Activate
You should consider to set objects to the workbooks and worksheets to avoid jumping between the windows.

Ciao,
Holger
 
Upvote 0
Ciao and patel45, Thank you both for your help.</SPAN>

Ciao, I don’t see the difference. Can you help?</SPAN>
 
Upvote 0
Hi, TylerV,

your code
Rich (BB code):
Windows("Fulfillment_Weekly_Headcount").Activate
Maybe it should be
Rich (BB code):
Windows("Fulfillment_Weekly_Headcount.xlsx").Activate
Like stated I assumed the extension of the workbook to be xlsx, you would need to change this to suit.

Ciao,
Holger
 
Upvote 0
Hi, TylerV,,

maybe this code will do what you want (you should alter the name for the range to clear contents), it will work between the workbook with the code and the workbook that needs to be opened.

Code:
Sub Macro1a()

Dim wbThis As Workbook
Dim wbNew As Workbook

Set wbThis = ThisWorkbook

wbThis.Sheets("Sheet_To_Clear").Range("E6:G6,E11:G26,E31:G38,E43:G43,E48:G48,E53:G53").ClearContents

On Error Resume Next
Set wbNew = Workbooks.Open(Filename:="c:\Reports\repory1__DB_Summary.csv")
On Error GoTo 0
If Not wbNew Is Nothing Then
  wbNew.ActiveSheet.Range("A2:K1044").Copy wbThis.Sheets("CR Sum").Range("A5")
  wbNew.Close False
End If
Set wbNew = Nothing

Set wbThis = Nothing
End Sub
Holger
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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