Code to move data from one spreadsheet to another

Woofy_McWoof_Woof

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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Fluff

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

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
1,261
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
42,421
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
40
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,101,904
Messages
5,483,635
Members
407,400
Latest member
Rakeforms

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top