+ Reply to Thread
Results 1 to 12 of 12

Copy Data Between 2 Workbooks

  1. #1
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Copy Data Between 2 Workbooks

    Dear Experts,

    I'm at entry level in VBA and usually can only modify recorded macros.

    Book1 with sheet named Transaction
    Book2 with sheet named TX

    The codes is intended to copy variable number of rows from Book1 to Book2, but fails at line 7 :

    1 Windows("Book1.xls").Activate
    2 Sheets("Transaction").Select
    3 Rows("9:9").Select
    4 Range(Selection, Selection.End(xlDown)).Select
    5 Selection.Copy
    6 Windows("Book2.xls").Activate
    7 Sheets("TX").Select
    8 Range("A9").Select
    9 Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    10 :=False, Transpose:=False

    Grateful if any can help. Thx so much!

  2. #2
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Copy Data Between 2 Workbooks

    try with replaceing Windows with Workbooks

    Please Login or Register  to view this content.
    Thanks - Naveed
    -----------------------------
    If the suggestion helps you, then Click * to Add Reputation
    To Attach File: Go Advanced>>Manage Attachments>>Add Files (In Top Right Corner)>>SelectFiles>>.........Locate Your File(s)>>Upload Files>>Done (In Bottom Right)
    1. Use [code] code tags [\code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  3. #3
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Copy Data Between 2 Workbooks

    Quote Originally Posted by Naveed Raza View Post
    try with replaceing Windows with Workbooks

    Please Login or Register  to view this content.
    Replaced Windows with Workbooks, but still stuck at line 7.

  4. #4
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Copy Data Between 2 Workbooks

    Here at my desk its working..............

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Copy Data Between 2 Workbooks

    Quote Originally Posted by Naveed Raza View Post
    Here at my desk its working..............

    Please Login or Register  to view this content.
    Thanks for your help. I've tried your codes which also work (except should add .xls to Book1 / Book2) ONLY IF I created new set of files for Book1 and Book2. That is, originally Book1 is actually an exported Excel account ledger Excel file which I suspect has been set with a different working environment that rendered the codes not working at line 7.

    So I wonder if there are any codes that can be set at top of the codes in order to restore the VBA environment variables to normal working environment, so that they can work with the exported account ledger Excel file.

    Kindly please further advise. Thx again.

  6. #6
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Copy Data Between 2 Workbooks

    hi,
    Naveed's code is working very well, here is an option to copy from a closed file, change the path for yr needs.
    Please Login or Register  to view this content.
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  7. #7
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Copy Data Between 2 Workbooks

    I'm little scared with your long string of characters. In any case, thanks for your kind help indeed.

    But in fact, my problem is only partially solved, because I still cannot understand why the codes do not work in my original Book2.xls file. Please advise how to send over to you for checking.

  8. #8
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Copy Data Between 2 Workbooks

    the only way is to upload those workbooks (1 and 2) having some data (removing sensitive data) and perhaps someone will help you

  9. #9
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Copy Data Between 2 Workbooks

    Quote Originally Posted by john55 View Post
    the only way is to upload those workbooks (1 and 2) having some data (removing sensitive data) and perhaps someone will help you
    In this case, I would be most grateful if you could help check the attached 2 files :
    Book1.xls and Book2.xls
    (macro in Book2.xls and Ctrl + i to execute, by copying data from Book1.xls to Book2.xls)
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Copy Data Between 2 Workbooks

    you have some Functions, I deleted them and it works, but check them...
    Please Login or Register  to view this content.
    try to add a button in Book2
    Please Login or Register  to view this content.
    Last edited by john55; 03-29-2015 at 04:34 AM. Reason: check yr Functions

  11. #11
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Copy Data Between 2 Workbooks

    Thank you for your advice, as I didn't realize there are other codes attached to each of the worksheet tabs. These codes should possibly be written by IT Dept for extraction of accounting data to Excel.

    These codes might have been sneaked into the Book2.xls file somehow when I tried to copy data. No wonder I found at times that the codes failed to work mysteriously on other occasions.

    I'm so happy that the problem can be solved, and thanks again.

  12. #12
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Copy Data Between 2 Workbooks

    Thank you for the feedback!

+ 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. Replies: 32
    Last Post: 09-16-2013, 01:40 AM
  2. Copy data between workbooks
    By arn0ldas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-04-2013, 06:36 AM
  3. Copy Data from 100 workbooks with cells into a master workbooks
    By roy__lam in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-10-2013, 02:11 PM
  4. I need to copy data from various workbooks into one master file, specific data
    By madhumith13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-21-2013, 09:14 AM
  5. [SOLVED] Copy data across workbooks
    By Copy multiple cells in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 01-11-2006, 08:25 PM

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