[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

Subscript out of range error

Hi,

I have the following line of code to copy/paste data from one spreadsheet to another

Im getting subscript out of range

The sheet "Prime Dividends Checker.xls" & sheet "PAID DIVS" are there.

Can anyone see why?

Thanks
Seamus




ThisWorkbook.Sheets("Sheet1").Range("A1").CurrentRegion.Copy _
        Workbooks("Prime Dividends Checker.xls").Sheets("PAID DIVS").Range("A" & Rows.Count).End(xlUp)(2)

Open in new window

0
Seamus2626
Asked:
Seamus2626
  • 3
  • 2
  • 2
1 Solution
 
Rory ArchibaldCommented:
If the workbooks and sheets are definitely correct then I'd say:
ThisWorkbook.Sheets("Sheet1").Range("A1").CurrentRegion.Copy _
        Workbooks("Prime Dividends Checker.xls").Sheets("PAID DIVS").Range("A" & Rows.Count).End(xlUp).Offset(1)

Open in new window

0
 
Seamus2626Author Commented:
Its worth mentioning ThisWorkbook is referring to a ss called "OPEN DIV RAW DATA" which is open and active

Does that make any difference?

I didnt think it would as this part of the code refers to the sheet i want to paste the data too
Copy _
        Workbooks("Prime Dividends Checker.xls").
0
 
Seamus2626Author Commented:
Got rid of ThisWorkbook!

Thanks
Seamus
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Rory ArchibaldCommented:
ThisWorkbook always refers to the workbook containing the code, not the active workbook.
0
 
StephenJRCommented:
ThisWorkbook always refers to the workbook containing the code. If this is not the case you will have to replace ThisWorkbook with the name of the workbook from which you are copying.
0
 
StephenJRCommented:
May be word for word but I swear I did not see your post rory!
0
 
Rory ArchibaldCommented:
No probs. :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now