Subscript Out of Range

Csmiley323

New Member
Joined
Apr 16, 2019
Messages
5
I am not sure what Im missing in this code but Im stumped. I need to take column values from one sheet and place them in different columns in another sheet. I have both files open and the sheet names are set as "Sheet1" but I keep getting a SubScript out of Range error. Any help or suggestions are appreciated. Thanks


'PG Description to TW Description Task and Title

Workbooks("PG.xlsm").Worksheets("Sheet1").Range("D2:D50").Copy
Workbooks("TW.xlsx").Worksheets("Sheet1").Range ("B2:B50")

Workbooks("PG.xlsm").Worksheets("Sheet1").Range("D2:D50").Copy
Workbooks("TW.xlsm").Worksheets("Sheet1").Range ("C2:C50")


'PG Start Date to TW Start Date

Workbooks("PG.xlsx").Worksheets("Sheet1").Range("E2:E50").Copy
Workbooks("TW.xlsx").Worksheets("Sheet1").Range ("O2:O50")



'PG Due Date to TW Due Date

Workbooks("PG.xlsx").Worksheets("Sheet1").Range("P2:P50").Copy
Workbooks("TW.xlsx").Worksheets("Sheet1").Range ("F2:F50")


'PG Status to TW Status

Workbooks("PG.xlsx").Worksheets("Sheet1").Range("F2:F50").Copy
Workbooks("TW.xlsx").Worksheets("Sheet1").Range ("J2:J50")
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi & welcome to MrExcel.
Which line is highlighted when you click debug?
Also these two lines should be one line of code
Code:
Workbooks("PG.xlsm").Worksheets("Sheet1").Range("D2:D50").Copy
        Workbooks("TW.xlsx").Worksheets("Sheet1").Range ("B2:B50")
 
Upvote 0
Actual Code from Editor




Private Sub CommandButton1_Click()

'PG Description to TW Description Task and Title

Workbooks("PG.xlsm").Worksheets("Sheet1").Range("D2:D50").Copy
Workbooks("TW.xlsx").Worksheets("Sheet1").Range ("B2:B50")

Workbooks("PG.xlsm").Worksheets("Sheet1").Range("D2:D50").Copy
Workbooks("TW.xlsm").Worksheets("Sheet1").Range ("C2:C50")


'PG Start Date to TW Start Date

Workbooks("PG.xlsx").Worksheets("Sheet1").Range("E2:E50").Copy
Workbooks("TW.xlsx").Worksheets("Sheet1").Range ("O2:O50")



'PG Due Date to TW Due Date

Workbooks("PG.xlsx").Worksheets("Sheet1").Range("P2:P50").Copy
Workbooks("TW.xlsx").Worksheets("Sheet1").Range ("F2:F50")


'PG Status to TW Status

Workbooks("PG.xlsx").Worksheets("Sheet1").Range("F2:F50").Copy
Workbooks("TW.xlsx").Worksheets("Sheet1").Range ("J2:J50")
 
Upvote 0
That line of code doesn't even appear in the code you've posted, but change the extension to xlsx
 
Upvote 0
Code:
Sub cs()
  Dim wksFr         As Worksheet
  Dim wksTo         As Worksheet  '

  Set wksFr = Workbooks("PG.xlsm").Worksheets("Sheet1")
  Set wksTo = Workbooks("TW.xlsx").Worksheets("Sheet1")

  With wksFr
    .Range("D2:D50").Copy wksTo.Range("B2")
    .Range("D2:D50").Copy wksTo.Range("C2")
    '...
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
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