Code to move data from one spreadsheet to another

Woofy_McWoof_Woof

New Member
Joined
Oct 7, 2016
Messages
34
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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,637
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
34
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,637
Office Version
365
Platform
Windows
What is the error message that you get?
 

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
1,073
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,637
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
34
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 :)
 

Forum statistics

Threads
1,089,546
Messages
5,408,873
Members
403,238
Latest member
George_Ong

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top