+ Reply to Thread
Results 1 to 24 of 24

How to copy worksheets to a new workbook

  1. #1
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    222

    How to copy worksheets to a new workbook

    I am trying to develop code top copy 3 worksheets to a new workbook,
    I have got this far but I am now stuck and could use some help.
    Please Login or Register  to view this content.
    This version stops at the line marked error with a "Subscript out of range" message which usually means a name doesn't exist.
    I think they are there.
    John

  2. #2
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    222

    Re: How to copy worksheets to a new workbook

    I forgot to add attachment
    Attached Files Attached Files

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Obviously restart just with the necessary ...


    As an unique codeline is necessary to copy 3 worksheets to a new workbook like this VBA demonstration :

    PHP Code: 
    Sub Demo0()
        
    Sheets(Array("LabelBudgetA""TapeBudgetA""TotalBudgeta")).Copy
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,984

    Re: How to copy worksheets to a new workbook

    Does this work for you?

    Please Login or Register  to view this content.
    Last edited by ByteMarks; 01-09-2024 at 05:04 PM.

  5. #5
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    222

    Re: How to copy worksheets to a new workbook

    ByteMarks Thanks for your interest. I had not thought of using an array. Before I plug your code into the app could you confirm the meaning of the line
    Please Login or Register  to view this content.
    Its the word CUT which worries me as I want the originals to remain..
    MarcL Thanks to you as well with the same basic idea as ByteManrks
    John

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,984

    Re: How to copy worksheets to a new workbook

    The cut moves the table to C2 of the sheet.
    For example TotalBudgeta_Table starts at F5 originally and is shifted to C2.

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How to copy worksheets to a new workbook

    I think ByteMarks misunderstood your initial code...
    As per Marc...this is all you need...substituting path and file name with yours...
    Please Login or Register  to view this content.
    Last edited by Sintek; 01-10-2024 at 12:06 PM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  8. #8
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,984

    Re: How to copy worksheets to a new workbook

    I think ByteMarks misunderstood your initial code...
    Possibly. It was from this line that I got the idea it had to be in C2.
    Please Login or Register  to view this content.
    However, you still might want to remove the Return buttons as they won't work in an xlsx

  9. #9
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How to copy worksheets to a new workbook

    However, you still might want to remove the Return buttons as they won't work in an xlsx
    See amended...
    Not any fault of yours...OP was trying to copy the sheets data to a new sheet within a new workbook and also copying the sheet...this initially confused me too...
    Last edited by Sintek; 01-10-2024 at 12:05 PM.

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to copy worksheets to a new workbook


    As the initial post is unclear, the reason why we could not 'understand' so my 'restart' help …

  11. #11
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    222

    Re: How to copy worksheets to a new workbook

    I seem to have confused all of you and in different ways too! I am sorry.
    What I want to achieve is this.
    At the present we have a budgeting app. This has 26 sheets, and all the calculations needed to account for our future costs and sales. It has 4 userforms and is a bit unwealdy.
    We have decided that we don't need to distribute this to all the people who have contributed to the app but we do need to tell them the results.
    So I need to make a small workbook with 3 sheets one for each of our product type Labels and Tapes and one for the total. The main app will still hold those three tables which will still be useful for next year
    I hope this makes a bit more sense. I need to form a new workbook and copy three worksheets to it.
    John.

  12. #12
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,984

    Re: How to copy worksheets to a new workbook

    sintek's Post #7 is probably the most complete solution, but include the lines you had originally to handle the DisplayAlerts when to saving to xlsx to avoid the "Macro free" warning.

  13. #13
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How to copy worksheets to a new workbook

    Quote Originally Posted by ByteMarks View Post
    sintek's Post #7 is probably the most complete solution, but include the lines you had originally to handle the DisplayAlerts when to saving to xlsx to avoid the "Macro free" warning.
    Don't need to...Newbook has no code...xlsx

  14. #14
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,984

    Re: How to copy worksheets to a new workbook

    Sorry, you're quite right. Pity there's no face palm emoji.

  15. #15
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How to copy worksheets to a new workbook

    More than welcome to take mine...I often make use of it lol...

    istockphoto-1316006857-612x612.png
    Last edited by Sintek; 01-10-2024 at 01:32 PM.

  16. #16
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,984

    Re: How to copy worksheets to a new workbook

    lol thanks.

  17. #17
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Talking Re: How to copy worksheets to a new workbook


    Such a big one ‼

  18. #18
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How to copy worksheets to a new workbook

    Quote Originally Posted by Marc L View Post

    Such a big one ‼
    You right...not such a big blunder lol...requires small one this time...updated...

  19. #19
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to copy worksheets to a new workbook


    Yes now big enough …

    That recalls me on another forum where I 'The Doctor' used a bid 'Dalek' « Explain ! » picture
    in order to make OP understand an Excel forum is very not a mind readers one …

  20. #20
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How to copy worksheets to a new workbook

    Hey...If you can't have fun coding...Then why do it...
    perhaps the forum will add more emoji's...more than enough coders to assist lol...

  21. #21
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    222

    Re: How to copy worksheets to a new workbook

    Quote Originally Posted by sintek View Post
    I think ByteMarks misunderstood your initial code...
    As per Marc...this is all you need...substituting path and file name with yours...
    Please Login or Register  to view this content.
    I am self taught in Excel and vba, and although everyone seems to have accepted sinteks code which I have quoted above, I am struggling to understand how it works.

    I cant see where the new workbook is added.
    The line Sheets(Array..... Doesn't have a workbook.
    The Activeworkbook in Line "With Activeworkbook" Seems to me to refer to the workbook with the code in it not the 3 sheets to be saved.
    I think that perhaps you have overrated me and have missed some lines that you think I know should be included.
    In any case it fails at the first lne.
    If sintek could explain for me it would be a great help.
    John

  22. #22
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How to copy worksheets to a new workbook

    I am self taught in Excel and vba
    Mee too...With the help of this amazing forum and it's members...And loving it...


    The only way it would fail on that line is if those 3 sheets do not exist...Code works for your sample supplied...
    Please Login or Register  to view this content.
    Attached Files Attached Files

  23. #23
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    222

    Re: How to copy worksheets to a new workbook

    Thankyou Sintek for the explanation of your code. I had not realised the depth of the Array line. As well as that I had not realised that three sheets had gone missing. Goodness knows the Budget sheets had been deleted but they were.
    Your code works fine now.
    Thanks too to the others who commented and helped.
    #John

  24. #24
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How to copy worksheets to a new workbook

    Glad to have contributed...Tx for rep +

+ 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. Replies: 4
    Last Post: 06-07-2019, 07:44 AM
  2. [SOLVED] VBA code to create a workbook and copy or move worksheets in to workbook through loop
    By anishkumarvs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-16-2015, 05:40 AM
  3. Replies: 12
    Last Post: 07-29-2014, 01:06 PM
  4. [SOLVED] Copy Specific Cells Across all worksheets in a Workbook and Paste Into single New Workbook
    By thunt13 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-14-2013, 10:43 AM
  5. Replies: 9
    Last Post: 06-24-2013, 04:14 PM
  6. Copy/Paste Range of Data from Multiple Workbooks/Worksheets to Master Workbook/Worksheets
    By NumberCruncher311 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-19-2013, 08:21 PM
  7. Copy multiple worksheets from 2003 workbook to one worksheet in 2010 workbook
    By KeithRoberts in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2012, 10:18 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