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.
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 here to see how.
Also, you might want to add to the user's reputation by clicking the scales icon - it's why we do what we do...
Thomas Lafferty
Analyst/Programmer
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?
You're going to want to look at the xldialogs collection:I haven't been able to find the proper xlDialog just yet.MoveChoice = Application.Dialogs(xlDialogSomething).Show
If your question has been satisfactorily addressed, please consider marking it solved. Click here to see how.
Also, you might want to add to the user's reputation by clicking the scales icon - it's why we do what we do...
Thomas Lafferty
Analyst/Programmer
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
If your question has been satisfactorily addressed, please consider marking it solved. Click here to see how.
Also, you might want to add to the user's reputation by clicking the scales icon - it's why we do what we do...
Thomas Lafferty
Analyst/Programmer
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.
Question: will it always be the same sheets to be copied?
If your question has been satisfactorily addressed, please consider marking it solved. Click here to see how.
Also, you might want to add to the user's reputation by clicking the scales icon - it's why we do what we do...
Thomas Lafferty
Analyst/Programmer
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.)
'Copy selected sheets to.... (user picks between the open workbooks, just like a normal excel sheet 'move.) UserChoice = Application.Dialogs(xlDialogWorkbookMove).Show
If your question has been satisfactorily addressed, please consider marking it solved. Click here to see how.
Also, you might want to add to the user's reputation by clicking the scales icon - it's why we do what we do...
Thomas Lafferty
Analyst/Programmer
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
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
If your question has been satisfactorily addressed, please consider marking it solved. Click here to see how.
Also, you might want to add to the user's reputation by clicking the scales icon - it's why we do what we do...
Thomas Lafferty
Analyst/Programmer
- 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.
can you attach a copy of the book the code runs from?
If your question has been satisfactorily addressed, please consider marking it solved. Click here to see how.
Also, you might want to add to the user's reputation by clicking the scales icon - it's why we do what we do...
Thomas Lafferty
Analyst/Programmer
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
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.
If your question has been satisfactorily addressed, please consider marking it solved. Click here to see how.
Also, you might want to add to the user's reputation by clicking the scales icon - it's why we do what we do...
Thomas Lafferty
Analyst/Programmer
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks