+ Reply to Thread
Results 1 to 6 of 6

Copying 3 given ranges to 3 sheets in a new workbook fails at second copy

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Copying 3 given ranges to 3 sheets in a new workbook fails at second copy

    I have a workbook which has, amongst many others, 3 sheets which each have a named range I want to copy and paste into another, new, workbook.
    The code I am trying to use was written several years ago and has worked without problems till now.
    Please Login or Register  to view this content.
    It fails at the second use of the do loop at the line marked ******* with a message "Subscript out of range" Perhaps there is no sheet2 ?
    I think that new workbooks used to open with 3 sheets when the code was written but perhaps with only 1 sheet now?
    I have not manged to solve this problem and would like some help please.

    I can confirm that there are three sheets with the names in the DO loop: and that these 3 all have a named range "Budget"
    On the first loop the new work book has been created and the Range "LabelBudgetA".Budget has been copied and pasted.
    The failure happens on the second loop.
    Thanks in anticipation
    John

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Copying 3 given ranges to 3 sheets in a new workbook fails at second copy

    Hi John

    The Macro is looking for three sheets named: LabelBudgetA, TapeBudgetA and TotalBudgetA

    Please Login or Register  to view this content.
    It uses N as a Counter.

    Please Login or Register  to view this content.
    Change this to the number of sheets plus 1 if you want to amend this.

    However the macro is over complicated.

    So I will simplify it so you can maintain it going forward.


    Please Login or Register  to view this content.
    Last edited by mehmetcik; 09-17-2020 at 09:46 AM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Copying 3 given ranges to 3 sheets in a new workbook fails at second copy

    You can set the number of worksheets to add to the new workbook

    Please Login or Register  to view this content.
    You probably need to set it back to 1 at the end or you will always have 3 sheets for new workbooks.
    Last edited by davesexcel; 09-17-2020 at 09:47 AM.

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

    Re: Copying 3 given ranges to 3 sheets in a new workbook fails at second copy

    Another Option...

    Your code does not show Save File Name...
    Please Login or Register  to view this content.
    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!!!

  5. #5
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Copying 3 given ranges to 3 sheets in a new workbook fails at second copy

    Many thanks for 3 interesting and different answers to my problem. I will try them all out and see which fits best.
    I must say that the way that this forum, or its contributors, work is a wonderful exception to much of modern life.
    I really am most grateful to you all.
    John

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

    Re: Copying 3 given ranges to 3 sheets in a new workbook fails at second copy

    .........................
    THANKS.gif

+ 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] vba to copy active visible sheets only to new workbook but ranges are dynamic
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2017, 12:48 PM
  2. Replies: 1
    Last Post: 01-09-2015, 04:18 AM
  3. Not able to copy formatting correctly while copying sheets to another workbook
    By pushkinpassey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-15-2014, 01:50 PM
  4. [SOLVED] Copy ranges from multiple sheets and paste them in another workbook
    By LewisM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2014, 09:26 AM
  5. [SOLVED] Copy Sheets From Another Workbook Without Named Ranges
    By Dikolis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-16-2009, 05:58 PM
  6. Filter Copy/Paste Fails - Two Ranges Selected?
    By Craigm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-15-2005, 11:16 AM
  7. named ranges and copying sheets to another workbook
    By helpwithXL in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-17-2005, 12:06 PM

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