+ Reply to Thread
Results 1 to 16 of 16

Copy only highlighted sheets from one workbook to another workbook

  1. #1
    Registered User
    Join Date
    11-28-2013
    Location
    PH
    MS-Off Ver
    Excel 2010
    Posts
    16

    Copy only highlighted sheets from one workbook to another workbook

    I need a macro to only copy those sheets with yellow highlight and save into another workbook.

    Can you add it in the macro below?

    Thanks!

    Here's the macro to copy and save to another workbook:

    Please Login or Register  to view this content.
    Last edited by arlu1201; 01-03-2014 at 01:36 AM. Reason: Use code tags in future.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy only highlighted sheets from one workbook to another workbook

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here


    Are the sheets themselves highlighted or the tabs for those sheets?
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    11-28-2013
    Location
    PH
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copy only highlighted sheets from one workbook to another workbook

    Sorry.

    It copy all sheets and doesn't highlight those with difference within the 2 workbooks

    Here's the code:

    Please Login or Register  to view this content.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy only highlighted sheets from one workbook to another workbook

    Hi JeffBoy,

    I've made some changes - but I can't test the program - so, take care!

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-28-2013
    Location
    PH
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copy only highlighted sheets from one workbook to another workbook

    Thanks xladept!

    What I need is a macro that can compare two sheets (with the same sheet name) in two different workbooks and save only the sheet of latest workbook with changes into a new file. I have two options below (any of the two options will do):

    Option 1:

    A macro that can compare two sheets (same tab name) in two different workbooks and saves only those sheet with changes in a new workbook.



    Option 2:

    A macro that can compare and highlight in yellow and saves only those with highlight in new workbook.

    Here's the script to highlight the difference in each sheet

    Please Login or Register  to view this content.
    Here's the script to save the file with changes, but this script saves all sheets.

    Please Login or Register  to view this content.
    Or just make a script that will copy only those sheets whose cells have highlight in yellow in a new workbook.

    Again, many thanks for your help.

    Thanks,

    Jeffboy
    Last edited by jeffboy29; 01-03-2014 at 05:33 AM.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy only highlighted sheets from one workbook to another workbook

    Hi Jeffboy,

    Are you saying that the changes I made in your program didn't work? What is your program not doing? Are you getting any error messages?

    Can you attach a sample workbook? Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  7. #7
    Registered User
    Join Date
    11-28-2013
    Location
    PH
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copy only highlighted sheets from one workbook to another workbook

    Hi Xladept,

    I have 2 files that needs to compare:

    Book 1 - current file w/ 3 sheets namely T0, T1 & T2
    Book 2 - previous file w/ 3 sheets namely T0, T1 & T2

    If there are changes in the sheets in book 1 by comparing it with book 2, it will save only the sheet with changes (in book 1) in a separate workbook and the filename will be the sheet name.

    You can highlight those cells with changes if you want (this is optional) the main purpose is to just save only those sheet that have changes.

    Example: T0.xls; T1.xls (assuming these are the sheets with changes)

    Book1:

    T0 - added A7 Code & Description (output should be T0.xls after comparing with Book2)
    T1 - no changes (no output file)
    T2 - added C7 Code & Description (output should be T2.xls after comparing with Book2)


    Hope you can help me.


    Thanks,

    Jeffboy
    Attached Files Attached Files

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy only highlighted sheets from one workbook to another workbook

    Hi Jeffboy,

    Here's a start:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-28-2013
    Location
    PH
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copy only highlighted sheets from one workbook to another workbook

    Thanks Xladept,

    However, I want that to save those with changes in a separate workbook. The code that you sent save it in the OutputBook.xls both the T0 & T1 sheets, it should be separate.


    Can you also change the workbook name in below code to standard (i'm having subscript out of range error) that's why i need to change it to Book1.xlsx and Book2.xlsx respectively.

    Please Login or Register  to view this content.
    Just to add that I also have T4, T5, T7, T8, T9 & PN sheets that I need to compare in addition to the T0, T1 & T2 (sorry i didn't include in the example).

    Another requirement is that the naming convention of the output file should be based on the parameter sheet (see attached file) can you include below script:

    MWIO_T5_2014-01-03.xls

    wherein

    MWIO is the Office Code located in "Parameter" sheet - B6
    T5 is the sheet name
    2014-01-03 is the date string

    Please Login or Register  to view this content.
    Thanks a lot for your help.


    Jeffboy
    Attached Files Attached Files
    Last edited by jeffboy29; 01-06-2014 at 02:03 AM.

  10. #10
    Registered User
    Join Date
    11-28-2013
    Location
    PH
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copy only highlighted sheets from one workbook to another workbook

    Hi Xladept,

    Here's the code that I'm working on now:

    Maybe you could edit to make it work. I'm having subscript out of range error.

    Please Login or Register  to view this content.
    Again, thank you very much for your help.


    Blessings!

    Jeffboy

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy only highlighted sheets from one workbook to another workbook

    Hi Jeffboy,

    I'm proceeding on the assumption that the previous book is just like the current one??

    Edit: Try this

    Please Login or Register  to view this content.
    BTW - you can either name your books Current and Previous or change my code.
    Last edited by xladept; 01-06-2014 at 05:32 PM.

  12. #12
    Registered User
    Join Date
    11-28-2013
    Location
    PH
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copy only highlighted sheets from one workbook to another workbook

    Hi Xladept,

    The previous workbook is the same with the current except that I added T4, T5, T7, T8, T9 & PN as additional sheets.

    Im having runtime error: method 'Copy' of object'Worksheet' failed on

    Please Login or Register  to view this content.

    The code is not working based on the requirements. Could you please check the script that I'm currently working.
    Maybe you could start from there.
    Thanks for your prompt response.

    Thanks!

    Jeffboy
    Last edited by jeffboy29; 01-06-2014 at 10:35 PM.

  13. #13
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy only highlighted sheets from one workbook to another workbook

    Hi Jeffboy,

    Are you running my code as written or have you made any changes??

    I ran it again - no problem??
    Last edited by xladept; 01-07-2014 at 04:39 PM.

  14. #14
    Registered User
    Join Date
    11-28-2013
    Location
    PH
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copy only highlighted sheets from one workbook to another workbook

    Hi Xladept,

    Thank you for your time.

    I tried to use your script below

    Please Login or Register  to view this content.
    Please see attached screenshot for "OutputBook"

    Comments:

    1. Is it possible not to use "Book1.xlsx" & "Book2.xlsx"? So that I will not rename the files that I will compare. The script must read that it needs to compare the two open excel files.

    2. The filename of the "OutputBook" should be

    MWIO_T5_2014-01-03.xls

    wherein

    MWIO is the Office Code located in "Parameter" sheet - B6
    T5 is the sheet name
    2014-01-03 is the date string

    3. The "OutputBook" doesn't save automatically.

    4. The outputbook includes all the sheets even if no data in it. Can you make it work to have only the sheets with changes and save each sheet as separate workbooks?

    5. The actual file that I'm going to use are the attached files below. Can you make the above script work on the attached files.


    Again thank you very much!


    Regards,

    Jeffboy29
    Attached Files Attached Files
    Last edited by jeffboy29; 01-08-2014 at 03:52 AM.

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy only highlighted sheets from one workbook to another workbook

    Hi Jeffboy,

    You should try the Post #11 program:

    Please Login or Register  to view this content.
    I'll try it this way: *Result** ran to completion - no messages - no problem??
    Last edited by xladept; 01-08-2014 at 03:53 PM.

  16. #16
    Registered User
    Join Date
    11-28-2013
    Location
    PH
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copy only highlighted sheets from one workbook to another workbook

    Hi Xladept,

    Thanks the script works on the sample files that I gave to you!

    One more thing, can you include this at the beginning of the script so that i will not rename the file as Book1, Book2, etc...

    Please Login or Register  to view this content.
    Can you also add message box saying "Report Completed. Please check folder for generated files" after running the script.



    Error:

    I'm running the script in the actual files (see attached files) that I'm working and I'm getting a Runtime error 1004 Method 'Copy' of object_Worksheet failed on

    Please Login or Register  to view this content.
    The COA Tracking Template_Vision XL is the current file where you will run the script.

    FYI:

    I have invisible sheet named Ls_XLB_WorkbookFile, maybe the error was with this sheet.


    Thanks a lot for your help.


    Regards,

    Jeffboy29
    Last edited by jeffboy29; 01-09-2014 at 09:14 AM.

+ 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 2 sheets from a open workbook and paste to a closed workbook
    By grimston in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-27-2012, 03:27 PM
  2. Replies: 4
    Last Post: 09-15-2012, 02:18 PM
  3. [SOLVED] Copy All Sheets From Each Workbook in Folder to a Single Sheet in New Workbook
    By DHartwig35805 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-21-2012, 03:53 PM
  4. Automatically Copy sheets in one workbook to create sheets in a new workbook..
    By leebarratt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-13-2011, 03:14 AM
  5. Replies: 0
    Last Post: 08-11-2011, 01:23 AM

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