+ Reply to Thread
Results 1 to 18 of 18

Copy Select Worksheets to User Defined Sheet?

Hybrid View

  1. #1
    Registered User
    Join Date
    09-20-2011
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    20

    Question Copy Select Worksheets to User Defined Sheet?

    I have workbook that has multiple sheets. When I push out a new version of this worksheet I want a user to be able to click a button to export all the sheets except "1" and "2" (for example) to the new workbook.

    So...
    1. the user clicks the button
    2. All sheets are copied except the three I specify in the VBA
    3. The screen comes up to allow the user to choose the workbook to export the sheets to

    I haven't been able to find anything on moving multiple sheets like this on the internet, only methods to move a single sheet (with a static name).

    What might this code look like? I really appreciate any help you can give me.

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Copy Select Worksheets to User Defined Sheet?

    I'd suggest a for next loop:
    for each s in sheets
         if s.index <> yournumber and s.index <> yourothernumber and s.index <> yourthirdnumber then
              for each w in workbooks
                   'put code here to put workbook names in variable for list on a user form
              next w
         end if
    next
    
    Userform1.show
    'code here to move sheets to chosen book
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  3. #3
    Registered User
    Join Date
    09-20-2011
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Copy Select Worksheets to User Defined Sheet?

    Could I make it simpler by just using that loop, saying move, and then have the normal excel "move or copy" box pop up for the user to select the open workbook to copy to? What might that code look like?

  4. #4
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Copy Select Worksheets to User Defined Sheet?

    You're going to want to look at the xldialogs collection:
    MoveChoice = Application.Dialogs(xlDialogSomething).Show
    I haven't been able to find the proper xlDialog just yet.

  5. #5
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Copy Select Worksheets to User Defined Sheet?

    Amended code:
    for each s in sheets
         if s.index <> yournumber and s.index <> yourothernumber and s.index <> yourthirdnumber then
                    MoveChoice = Application.Dialogs(xlDialogSomething).Show
         end if
    next

  6. #6
    Registered User
    Join Date
    09-20-2011
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Copy Select Worksheets to User Defined Sheet?

    would it be xldialogmove?

    Maybe it would be smart to use that, but put all the items in an array first? Otherwise won't that box show for every tab? It would be nice to add them to an array, then move them all at once. I'm not very familiar with putting sheets into an array and then calling it at all.

    By the way, thanks so much for your help. I was really struggling with this.

  7. #7
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Copy Select Worksheets to User Defined Sheet?

    Question: will it always be the same sheets to be copied?

  8. #8
    Registered User
    Join Date
    09-20-2011
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Copy Select Worksheets to User Defined Sheet?

    No. But it is always the same sheets that won't be copied (that should help a lot.)

    I've got this code below that selects the sheets I need, with your help. How can I now just show the excel move dialog and let the user move the selected sheets?

    Dim ws As Worksheet
    
    For Each ws In Sheets
    
        If ws.Visible And ws.Name <> "Instructions" And ws.Name <> "Chart Data" And ws.Name <> "Project-Chart" Then ws.Select (False)
    Next
    
    'Copy selected sheets to.... (user picks between the open workbooks, just like a normal excel sheet 'move.)

  9. #9
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Copy Select Worksheets to User Defined Sheet?

    'Copy selected sheets to.... (user picks between the open workbooks, just like a normal excel sheet 'move.)
    UserChoice = Application.Dialogs(xlDialogWorkbookMove).Show

  10. #10
    Registered User
    Join Date
    09-20-2011
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Copy Select Worksheets to User Defined Sheet?

    one last issue that I didn't predict. When it copies, it also adds the external references. Is there anyway I can edit this code so it will copy/move the sheets, keep the formulas, but not add the external references?

    Thank you so much for your help so far. I did add to your reputation on the site btw :-)

    Sub CopySheets()
    Dim ws As Worksheet
    
    For Each ws In Sheets
    
        If ws.Visible And ws.Name <> "Instructions" And ws.Name <> "var" And ws.Name <> "Chart Data" And ws.Name <> "Project-Chart" Then ws.Select (False)
    Next
    UserChoice = Application.Dialogs(xlDialogWorkbookMove).Show
    
    End Sub

  11. #11
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Copy Select Worksheets to User Defined Sheet?

    Are you copying the sheets or removing them (move)? Also, are the external references to named ranges in your formula, or are they references to the original sheet location? ie: sheet 1 gets moved to book 2, and the formulas now look like:
    =[Book1]Sheet1!$A$1
    Last edited by tlafferty; 09-20-2011 at 05:49 PM. Reason: typo

  12. #12
    Registered User
    Join Date
    09-20-2011
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Copy Select Worksheets to User Defined Sheet?

    - I'd like to move them... if it is somehow easier to copy that would work too though.
    - The reference is to the sheet location C:// I found a way to remove the link manually and change the source to the current file, but using the macro recorder I could not find a way to make this work under any sheet-name circumstance -- so I couldn't figure out the automation.

  13. #13
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Copy Select Worksheets to User Defined Sheet?

    can you attach a copy of the book the code runs from?

  14. #14
    Registered User
    Join Date
    09-20-2011
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Copy Select Worksheets to User Defined Sheet?

    There are many unused macros. Now we can talk more specifically.

    All of those tabs that have the numbers as names (dates), are the ones that need to get copied when I make changes to the other tabs/macro's. In essence it is a way to rollout changes and help people easily transfer data if we have big changes.

    Please excuse the simplicity of this sheet! It is in its infantile stages. You should see the copy macro in there somewhere. There are also many unused macros.
    Last edited by mayhem12; 09-22-2011 at 05:02 PM. Reason: Removed Attachment

  15. #15
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Copy Select Worksheets to User Defined Sheet?

    I noticed a LOT of named ranges in your book, some scoped to the workbook, but most scoped to the sheet. What procedure are you using to make the changes, and maybe I can automate that.

  16. #16
    Registered User
    Join Date
    09-20-2011
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Copy Select Worksheets to User Defined Sheet?

    Hm I think a lot of those named ranges aren't used.

    What I'm thinking as far as the changes was just to push a new excel spreadsheet out to people and they would click the button to bring in all of their project data (those date tabs). I'm not sure if this is what you mean by changes. I will be continuing to optimize this workbook so eventually when version 4 comes out, I want people to be able to make a really easy transition ( a lot of people don't know or would have a ton of trouble copying sheets and updating the values to get rid of links)

  17. #17
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Copy Select Worksheets to User Defined Sheet?

    Sorry about the ambiguity of my question. I meant to ask what you meant by:
    - The reference is to the sheet location C://
    and how you go about locating the reference and changing it. Also, I'd recommend copying rather than moving sheets since I noticed that removing sheets from the workbook will cause reference errors in the Chart-Data sheet and probably the Project-Chart sheet as well.

  18. #18
    Registered User
    Join Date
    09-20-2011
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Copy Select Worksheets to User Defined Sheet?

    So to duplicate the problem/situation you would simply make a copy of this workbook, then try to copy the date tabs into it.

    By the reference I was saying that when I copied excel had "external references" to the workbook I copied from. So it was referencing the workbook on my c drive that I copied the data from.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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