+ Reply to Thread
Results 1 to 8 of 8

Copy data from one workbook, paste it to another

  1. #1
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Copy data from one workbook, paste it to another

    Hi,

    I'm trying to solve this little problem, but no luck so far. I work with workbooks for customer orders each having a different name. I open it, work on it, then I need to bring data from a second book (this one with a fixed name/location), and paste it onto the customer order's one, then close the copying book without saving changes. The code I have, does open the copying workbook, and copies the data (column A), but does not paste it at all in the customer order's book.

    What do I have to adjust? ... This is the code, so far:

    Sub Open_Copy_Paste()

    Workbooks.Open("C:\Users\DVD\MASTER.xlsx").Activate
    Range("A2").Select
    Range(Selection, Selection.End(xlDown)).Copy

    ThisWorkbook.Cells(1).Range("A1").PasteSpecial

    Workbooks("MASTER.xlsx").Close SaveChanges:=False


    End Sub


    Thanks!

  2. #2
    Registered User
    Join Date
    01-12-2017
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Office 2010
    Posts
    8

    Re: Copy data from one workbook, paste it to another

    This should solve your problem.

    Please Login or Register  to view this content.
    Sheets(1) might change in your case. If you want to specify the sheet name, just replace Sheets(1) with .Sheets("YourSheetName")

  3. #3
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Copy data from one workbook, paste it to another

    Hi ssaidli,

    First of all, thanks for your help! I used the code you posted, but the column is still not pasted to the current book. The code ended like this:

    Workbooks.Open("C:\Users\DVD\MASTER.xlsx").Activate
    Range("A2").Select
    Range(Selection, Selection.End(xlDown)).Copy

    ThisWorkbook.Sheets(1).Range("A1").PasteSpecial xlPasteValues

    Workbooks("MASTER.xlsx").Close SaveChanges:=False

    Using "Sheets(1)" is better I think, since this macro is to be run on a different workbook each time, but the copied info will always be pasted to the first sheet.

    Not sure what's going on? ...

  4. #4
    Registered User
    Join Date
    01-12-2017
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Office 2010
    Posts
    8

    Re: Copy data from one workbook, paste it to another

    See the link below. This thread is not about copy-paste but I have attached my full code which might help you finding what you need. This code copies data from one workbook onto another and closes them afterwards.
    http://www.excelforum.com/showthread.php?t=1170026

  5. #5
    Registered User
    Join Date
    01-12-2017
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Office 2010
    Posts
    8

    Re: Copy data from one workbook, paste it to another

    Try this code as well.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Copy data from one workbook, paste it to another

    Hi Ssaidli,

    I tried the code you posted, but I get a "Run-time error '91': Object variable or With block variable not set". When clicking on "Debug", takes me to this line: workbook1 = Workbooks.open(path)

    I read the link for the other post, but was a bit too complicated for me.

    I'll try to figure out what's going on. If you happen to have an additional comment, it'll be appreciated.

    Thanks!

  7. #7
    Registered User
    Join Date
    01-12-2017
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Office 2010
    Posts
    8

    Re: Copy data from one workbook, paste it to another

    Sorry about that. Should be
    Please Login or Register  to view this content.
    See I am no professional in excel VBA, I am a learner too, but this seems like a simple problem to me. If you could go to the link I provided and tweak and change the parts of it, you can actually get it working.

  8. #8
    Registered User
    Join Date
    04-20-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: Copy data from one workbook, paste it to another

    Hi again,

    Well, I added the piece of code, but the info still doesn't get pasted at all. Yes, I agree with you, this should be a simple to solve issue. As for the link you provided, as I mentioned, I visited it, and read all info there. However, if you're not a professional, I'm certainly way behind your level, 'cause I didn't really understand most of the code.

    I do, however, appreciate your help. Certainly gave me some more understanding about this. I'll keep experimenting and doing research.

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to find data in source workbook and copy paste to target workbook
    By D.Lovell in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-23-2014, 06:21 AM
  2. Replies: 6
    Last Post: 03-26-2014, 11:40 PM
  3. [SOLVED] Code to copy data from a closed workbook and paste in active workbook using named range.
    By paullie1912 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-28-2014, 02:38 AM
  4. Replies: 6
    Last Post: 01-29-2013, 07:01 AM
  5. [SOLVED] Copy/paste data from one workbook to another but workbook name variable
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-11-2013, 12:14 PM
  6. Copy data from workbook, create new workbook, paste data to new worbook?
    By mpkavanagh in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-16-2011, 06:39 PM
  7. [SOLVED] Selecting data from 1 workbook to copy and paste to a 2nd workbook
    By JackSpam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2005, 10:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1