+ Reply to Thread
Results 1 to 9 of 9

Copy sheets from two workbooks to another workbook

  1. #1
    Registered User
    Join Date
    08-11-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    58

    Copy sheets from two workbooks to another workbook

    Hi All,

    I tried searching forums to do the below function, unfortunately could not find it.
    I am struggling with the code, however it does almost what I want but have one issue.

    Problem Definition:
    I have two workbooks:
    1. Book1 and sheets in this workbook are as follows TC1, TC2,TC3,TC4
    2. Book2 and sheets in this workbook are as follows AC1, AC2, AC3, AC4

    When I run a macro, specific sheets named in the code from Book1 and Book2 will be copied in Book3 with same sheet names.
    Once copied, Book1 and Book2 and Book3 should close and be placed in the same folder.

    I am trying to run the below code, forgive me for the logic, however am stuck.
    The below code copies and pastes on one sheet only and does not add a new sheet.

    I am fairly ok in macros but get stuck in looping. The below code was developed by my colleague and I am posting here.

    Kindly request you all to help me out on the below.

    Best Regards,
    Sri

    Please Login or Register  to view this content.
    Last edited by sreeks; 03-28-2014 at 01:54 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Copy sheets from two workbooks to another workbook

    The code doesn't seem to match the description.

    For one thing it involves Book1, Book2, Book4 and Book5.

    Also, what's happening here?
    Please Login or Register  to view this content.
    You appear to be looking for a workbook called Book1.xlsx, if it doesn't exist you are creating a new workbook and trying to name it Book4.xlsx.

    When creating a new workbook you can't name it.

    Also, after creating the new workbook you try and open it, the workbook hasn't been saved yet.

    Which worksheets do you want to copy from which workbooks?

    Which workbooks are open when you run the code?

    Do you want to copy the worksheets or the data from the worksheets?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-11-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Copy sheets from two workbooks to another workbook

    Hi Norie,

    Thank you so much for your help and quick response.


    Below are the comments:

    Which worksheets do you want to copy from which workbooks?
    I would like to copy specific sheets from workbooks, I am ok if we can provide the source sheet name in the macro
    This way for different scenario, I will change the sheet name to copy in the macro it self for both InputBook1 and InputBook2


    For example:
    1. InputBook1 has three sheets "attributes_s", "ag_id", "tbr_detail", "X", "Y" and "Z"
    2. InputBook2 has three sheets "arrangement_s", "X" and "Y"

    Objective:
    1. Open InputBooks, copy specified sheets from these two books and paste it in the OutputBook1 i.e.
    a) Copy "attributes_s", "ag_id", "tbr_detail" from InputBook1
    b) Copy "arrangement_s" from InputBook2
    c) Paste the above sheets in OutputBook1





    Which workbooks are open when you run the code?
    Both the Input books should be closed. However both input books will be in same folder


    Do you want to copy the worksheets or the data from the worksheets?
    I would like to copy the sheet itself along with its name.

    Thank you once again for your support this would mean a lot to me and save like huge amount of hours.

    Best Regards,
    Srikanth
    Attached Files Attached Files
    Last edited by sreeks; 03-28-2014 at 12:35 PM.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Copy sheets from two workbooks to another workbook

    Perhaps this will give a start.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-11-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Copy sheets from two workbooks to another workbook

    Hi Norie,

    Just able to really appreciate, the code I shared earlier was so many lines and we were really scratching our brains.
    The code you shared is so simple and organized and logic is implemented perfectly.

    However, once compiled it is showing an error message at this line:

    Run-time error '9':
    Subscript out of range
    Please Login or Register  to view this content.
    Best Regards,
    Sri
    Last edited by sreeks; 03-28-2014 at 01:02 PM. Reason: Add info

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Copy sheets from two workbooks to another workbook

    Check the sheets in your workbooks, the second input workbook only has 1 sheet.

  7. #7
    Registered User
    Join Date
    08-11-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Copy sheets from two workbooks to another workbook

    Hi Norie,

    It worked like charm...Phew...
    Thanks you so much, it just made our lives so easier.

    One last help would be the below situation.
    Kindly request you to have a look at the below and please advise.


    1. We have A,B,C,DE scenarios and we need to create 6 sheets for all the scenarios and a "Result" sheet in the spreadsheet which you helped us create i.e. Book3:
    ATC1.....ATC6 - All A in Black colour
    BTC1.....BTC6 - All B in Yellow colour
    CTC1.....CTC6 - All C some Light Blue
    DETC1.......DETC6 - All D some Light Grey
    Results - This will be Green color

    I did a manual work around by recording a macro:
    Create Sheet
    Rename as ATC1
    Coloured sheet as mentioned above.
    Copy paste for each sheet name which will be around 25 times of the below code snippets but ofcourse change colour and change sheet names.

    Please Login or Register  to view this content.
    I am managing by doing the above, if there is an easy workaround, please advise.

    Best Regards,
    Sri

  8. #8
    Registered User
    Join Date
    08-11-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Copy sheets from two workbooks to another workbook

    Hi Norie,

    Thank you for the support...
    Please let me know if there is an easy workaround for the above.

    Best Regards,
    Sri
    Last edited by sreeks; 03-28-2014 at 01:39 PM. Reason: Working as expected

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Copy sheets from two workbooks to another workbook

    Sri

    Might be an idea to start a new thread for this new question.

+ 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. Copy Sheets from multiple workbooks and add them to master workbook
    By tjkain in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-30-2013, 10:15 AM
  2. [SOLVED] VBA to copy certain sheets from various workbooks into new workbook
    By Alice21 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2013, 11:05 AM
  3. Copy a first sheet of a workbook in the first sheets of other workbooks
    By khracking in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-29-2012, 05:10 PM
  4. Copy sheets from different workbooks to specific sheets in one workbook
    By erikfae in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-16-2011, 08:02 AM
  5. copy sheets from workbooks to one workbook
    By soso123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2011, 05:53 AM

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