Code to move data from one spreadsheet to another

Woofy_McWoof_Woof

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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Fluff

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

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
1,319
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,956
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
42
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,102,872
Messages
5,489,430
Members
407,689
Latest member
Doublealpha

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top