Results 1 to 3 of 3

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

Threaded View

  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:

    Sub CopyWorksheetXTimes()
        Dim x As Integer
        
        x = InputBox("Enter number of times to copy Near leader output sheet 1")
        For numtimes = 1 To x
            ActiveWorkbook.Sheets("Near leader output sheet 15").Copy _
                after:=ActiveWorkbook.Sheets("Near leader output sheet 15")
        Next
        
    End Sub
    Any help would be much appreciated
    Last edited by TBG; 11-29-2012 at 10:49 PM. Reason: Added code tags

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