+ Reply to Thread
Results 1 to 8 of 8

Copy Workbook Sheets, Keep Certain Sheets, Set Visibility

  1. #1
    Forum Contributor
    Join Date
    11-10-2011
    Location
    New York, NY
    MS-Off Ver
    MS Office: Excel 365
    Posts
    163

    Copy Workbook Sheets, Keep Certain Sheets, Set Visibility

    Hi --

    Looking for VBA ideas
    I have a file with a large amount of sheets. To create an end-user version, I'd like to do the following:

    1. Copy all sheets to new workbook
    2. Delete sheets not listed in specified table (say, Table1)
    3. Set visibility properties of remaining sheets per defined value in Table1

    Table1 is a pre-populated excel table that lists a couple sheet names (Table1[Sheets to Keep]), and has a column next to each sheet name with either -1, 0, or 2 (Table1[Sheet Visibility]).

    Only the sheets I wish to keep are listed in Table1, all other sheets are to be deleted.

    What would you suggest as the best/most efficient way to approach #s 2 and 3 above?

    Thank you!

    -k

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,101

    Re: Copy Workbook Sheets, Keep Certain Sheets, Set Visibility

    It would be easier to help and test possible solutions if you could attach a copy of your file. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary). See the yellow banner at the top of this page for instructions to attach a file.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Contributor
    Join Date
    11-10-2011
    Location
    New York, NY
    MS-Off Ver
    MS Office: Excel 365
    Posts
    163

    Re: Copy Workbook Sheets, Keep Certain Sheets, Set Visibility

    Hi --

    Please see attached

    No changes should be made to any contents on any of the sheets.

    Steps needed are:

    1. Sheets to be copied to a separate workbook (all sheets, so that no dependant formulas on a sheet reference the original file).
      For this I was planning to just use 'ActiveWorkbook.Sheets.Copy'.
    2. Sheets not listed in Table1 to be deleted
    3. Remaining sheets visibility properties to be set via the value in 'Sheet Visibility' column (-1 = Visible, 0 = Hidden, 2 = Very Hidden)

    Note that in the original file, some sheets are Hidden & Very Hidden.
    Also, the new file doesn't need to be Saved or Saved As anything, you can keep as Book1, or whatever Excel defaults to.

    Please let me know if you have any other questions/comments.
    Thank you!

    -k
    Attached Files Attached Files

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,101

    Re: Copy Workbook Sheets, Keep Certain Sheets, Set Visibility

    This was a little more complicated than I thought. Try this macro:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-10-2011
    Location
    New York, NY
    MS-Off Ver
    MS Office: Excel 365
    Posts
    163

    Re: Copy Workbook Sheets, Keep Certain Sheets, Set Visibility

    Thanks for looking into it!

    I looked at what you sent and also took a stab at a solution that's a bit more legible for intermediate users, like myself.
    The only remaining issue is that 'ActiveWorkbook.Sheets.Copy' doesn't seem to copy over VeryHidden sheets, so my only solution may be to use 'ActiveWorkbook.SaveCopyAs' instead.
    (I was hoping to avoid this since the destination file path could be different, depending on who's running the code)

    If you can think of a way to duplicate the entire file (incl. VeryHidden sheets) without having to save the resulting workbook, that'd be great. If not, all good.
    In case you were interested, here's where I landed (note that I changed 'Sheet X's visibility to -1 since that sheet has the reference table and needs to be visible).:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,101

    Re: Copy Workbook Sheets, Keep Certain Sheets, Set Visibility

    Is everything working for you now?

  7. #7
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Copy Workbook Sheets, Keep Certain Sheets, Set Visibility

    Possibly so?

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    11-10-2011
    Location
    New York, NY
    MS-Off Ver
    MS Office: Excel 365
    Posts
    163

    Re: Copy Workbook Sheets, Keep Certain Sheets, Set Visibility

    Hi --

    This doesn't seem to duplicate the file, only perform the deletions within the existing file which is no longer an issue for me.
    The outstanding question is whether I can duplicate an entire file (incl. Very Hidden sheets & without moving the sheets one-by-one), all while keeping the original file open/unsaved.
    I'm not familiar w/ some of the functions you're using so it's not clear if yours accomplishes this aim, but it doesn't seem that it does.

    Thank you

+ 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] Copy Sheets from Closed Workbook into Open Active Workbook without linking
    By CHRISOK in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-16-2018, 04:54 PM
  2. [SOLVED] VBA code - using formulas based on sheets visibility
    By Tapyr in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-17-2016, 09:24 AM
  3. Replies: 0
    Last Post: 07-01-2015, 03:33 PM
  4. [SOLVED] Macro to copy cells from multiple sheets in workbook to multiple sheets in other workbook
    By KeithMale in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-13-2013, 05:37 PM
  5. [SOLVED] Copy All Visible Sheets To New Workbook Excluding Specific Sheets
    By ezrizer in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-19-2012, 02:19 PM
  6. 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
  7. 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

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