Code to move data from one spreadsheet to another

Woofy_McWoof_Woof

New Member
Joined
Oct 7, 2016
Messages
36
Hi, I'm trying to move data from one spreadsheet to another (instead of using a copy and paste code which uses too much memory). I'm trying to reduce a 70MB file down to something more manageable and think removing the copy and paste function will help a lot.

In workbook "Book1" I'm trying to move data from sheetx to sheety in workbook "Book2" however I'm getting the nasty debug error (runtime error 9)

Windows("Book1.xlsx").Activate
Sheets("Sheetx").Range("B10:AX5000").Copy Destination:=Windows("Book2.xlsx").Activate.Sheets("Sheety").Range("A2:AX5000")


Any ideas? Thanks in advance

Woof
 

Some videos you may like

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,776
Office Version
365
Platform
Windows
Try
Code:
Sheets("Sheetx").Range("B10:AX5000").Copy Destination:=workbooks("Book2.xlsx").Sheets("Sheety").Range("A2")
 

Woofy_McWoof_Woof

New Member
Joined
Oct 7, 2016
Messages
36
Thanks for this, but I'm still getting the run time error. I'm assuming that it could be that the macro is saved in "Book2" rather than "Book1", apologies for not mentioning that. I need to pull the data into book2 rather than push it from book1 (as I will be replicating the code several times for several different sheets). Will that make a difference to the code?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,776
Office Version
365
Platform
Windows
What is the error message that you get?
 

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
1,077
Office Version
2010
Platform
Windows
Windows("Book1.xlsx").Activate
Sheets("Sheetx").Range("B10:AX5000").Copy Destination:=Windows("Book2.xlsx").Activate.Sheets("Sheety").Range("A2:AX5000")
If your macro is in Book2, then the extension cannot be xlsx since this type of file prohibits macros. I would presume that it is xlsm. I suggest changing the extension and seeing if that solves your problem
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,776
Office Version
365
Platform
Windows
That error signifies that one of the workbook names (including extension) or sheet names is wrong.
 

Woofy_McWoof_Woof

New Member
Joined
Oct 7, 2016
Messages
36
Perfect, it works. I'll replicate it for the other tabs and hopefully it will reduce the memory size of the file. Thanks very much for your help :)
 

Watch MrExcel Video

Forum statistics

Threads
1,089,785
Messages
5,410,406
Members
403,316
Latest member
samhadian

This Week's Hot Topics

Top