+ Reply to Thread
Results 1 to 3 of 3

Copy existing sheet and rename from a list on a different sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    07-02-2017
    Location
    wales
    MS-Off Ver
    2013
    Posts
    1

    Unhappy Copy existing sheet and rename from a list on a different sheet

    Hi i hope you can help i am very new to this and have a understanding of the very basics.

    i am creating a database for my clients and on the page named "clients" there is a list of clients that i keep adding to and when i add one i would like it to automatically copy a template sheet named "assesment" and rename it after that client.

    I understand how to open the coding window but ive tried lots of diffrent codes but im getting no reactions please help.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy existing sheet and rename from a list on a different sheet

    Where to put the code depends on the rest of the code but something like




    Dim wt as worksheet:Set wt=Sheets("Template Sheet Name")
    
    . 
    .
    .
    wt.Copy After:=Worksheets(Worksheets.Count)
    ActiveSheet.Name="Client's Name"
    .
    .
    .
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,446

    Re: Copy existing sheet and rename from a list on a different sheet

    .
    Paste this macro into a Routine Module.

    
    Sub HyperLnksCreate()
    Dim wsRecipes As Worksheet, wsTEMP As Worksheet, wasVISIBLE As Boolean
    Dim shNAMES As Range, Nm As Range
    Dim i As Long
    Dim wsIndex
    On Error Resume Next
    
    With ThisWorkbook                                               'keep focus in this workbook
        Set wsTEMP = .Sheets("Template")                            'sheet to be copied
        wasVISIBLE = (wsTEMP.Visible = xlSheetVisible)              'check if it's hidden or not
        If Not wasVISIBLE Then wsTEMP.Visible = xlSheetVisible      'make it visible
        
        Set wsIndex = .Sheets("Index")                            'sheet with names
                                                                    'range to find names to be checked
        Set shNAMES = wsIndex.Range("A2:A" & Rows.Count).SpecialCells(xlConstants)     'or xlFormulas
        
        Application.ScreenUpdating = False                              'speed up macro
        For Each Nm In shNAMES                                          'check one name at a time
            If Not Evaluate("ISREF('" & CStr(Nm.Text) & "'!A2)") Then   'if sheet does not exist...
                wsTEMP.Copy After:=.Sheets(.Sheets.Count)               '...create it from template
                'ActiveSheet.Range("A1").Value = (Nm.Text)
                ActiveSheet.Name = CStr(Nm.Text)                        '...rename it
             End If
             
        With Sheets("Index")                                                         'create hyperlinks in list
            For i = 2 To .Range("A" & .Rows.Count).End(xlUp).Row
            .Hyperlinks.Add Anchor:=.Range("A" & i), Address:="", _
            SubAddress:="'" & .Range("A" & i).Value '& "'!A2" ', TextToDisplay:=.Range("A" & i).Value
            Next i
        End With
    
        Next Nm
        
        wsIndex.Activate                                           'return to the master sheet
        If Not wasVISIBLE Then wsTEMP.Visible = xlSheetHidden       'hide the template if necessary
        Application.ScreenUpdating = True                           'update screen one time at the end
    
    End With
    
    MsgBox "All sheets created"
    End Sub
    In your workbook, name the Sheet1 as TEMPLATE. Name Sheet2 as INDEX. Arrange the TEMPLATE sheet as a complete, blank form.

    On INDEX, A1 ... enter SALESMAN NAMES.

    Place a command button next to that in B1, and connect the button to the above macro.

    Beginning in A2, type the name of a salesman. In A3 repeat, A4 repeat, etc. At any time you can add a new name to the bottom of the list.

    The macro creates only new sheets - does not overwrite existing sheets.
    Attached Files Attached Files

+ 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: 9
    Last Post: 03-28-2017, 08:30 PM
  2. [SOLVED] various cases in same sheet; copy sheet and rename according to list
    By missbogota in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-21-2017, 11:23 AM
  3. [SOLVED] Copy Template Sheet and rename the new sheets based on a list in another sheet
    By SaadKiji in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2016, 11:47 AM
  4. Rename existing worksheets from list on sheet 1
    By DedraMae in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-14-2013, 10:54 AM
  5. Rename existing tabs from list on sheet 1
    By DedraMae in forum Excel General
    Replies: 1
    Last Post: 11-12-2013, 12:26 PM
  6. Replies: 0
    Last Post: 04-28-2012, 06:06 PM
  7. Copy and rename a sheet in an existing workbook?
    By robertse in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-09-2010, 02:00 PM

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