+ Reply to Thread
Results 1 to 3 of 3

VBA loop to copy a worksheet a number of times, assign name each time based on loop number

  1. #1
    Registered User
    Join Date
    11-29-2012
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    8

    VBA loop to copy a worksheet a number of times, assign name each time based on loop number

    I'm looking to create a macro which will run a for...next loop 74 times (i=1 to 74) to copy a worksheet and name it dynamically based on the loop number. I'm not smart/experienced enough to do both within the same macro, so I could use some help from ya'll knowledgeable folks.

    So I want to do the following steps:

    Copy worksheet "Near leader output sheet 1" to the end of the workbook
    Name new sheet "Near leader output sheet i+1" '<name contains a number based on the current number of the loop
    repeat i times

    I was using a simple macro to copy the worksheet a set number of times, but it has stopped working due to repeated name issues (I also can't copy worksheets by hand anymore more than once - excel seems to have forgotten how to automatically assign higher numbers to copied worksheets)

    My current, non functional code which does not rename:

    Please Login or Register  to view this content.
    Any help would be much appreciated
    Last edited by TBG; 11-29-2012 at 10:49 PM. Reason: Added code tags

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: VBA loop to copy a worksheet a number of times, assign name each time based on loop nu

    hi
    looks like you're almost there with your macro

    try this variation (I've set it to copy file "Near leader output sheet 1", not file 15)

    Please Login or Register  to view this content.
    can I ask you to edit your post and put code tabs around the macro code - otherwise a moderator will ping you!

  3. #3
    Registered User
    Join Date
    11-29-2012
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VBA loop to copy a worksheet a number of times, assign name each time based on loop nu

    Thanks Nicky, worked perfectly, you're the best!

    Also appreciate the help on the code tagging - didn't realize.

+ 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