Duplicate template based on refreshed list
Results 1 to 5 of 5

Thread: Duplicate template based on refreshed list
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Feb 2015
    Posts
    35
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Duplicate template based on refreshed list

    I have a workbook that has a template on a sheet named "template".
    I have another sheet names "People" that has a table that refreshes each day based a query. On column A it has a list of people's first and last names

    Goal: After the I refresh the query (separate macro), I want the new macro to copy the template and create a new sheet for each name on Column A "People" worksheet. Rename new sheet with template copied the persons first name and last initial, if a duplicate occurs simply rename Bob A(2)

    Hopefully that makes sense.

    Thanks for any help!

  2. #2
    New Member
    Join Date
    Feb 2015
    Posts
    35
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Duplicate template based on refreshed list

    Figured it out * Found it

    Option Explicit
    Sub NewSheets()
    Dim i As Integer
    Dim ws As Worksheet
    Dim sh As Worksheet
    Set ws = Sheets("Template")
    Set sh = Sheets("Sheets Insert")
    Application.ScreenUpdating = 0

    For i = 2 To Range("A" & Rows.Count).End(xlUp).Row
    Sheets("Template").Copy After:=sh
    ActiveSheet.Name = sh.Range("A" & i).Value
    Next i
    End Sub

  3. #3
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,310
    Post Thanks / Like
    Mentioned
    50 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Duplicate template based on refreshed list

    Quote Originally Posted by JAnders View Post
    Figured it out * Found it

    Code:
    Option Explicit
    Sub NewSheets()
        Dim i As Integer
        Dim ws As Worksheet
        Dim sh As Worksheet
        Set ws = Sheets("Template")
        Set sh = Sheets("Sheets Insert")
        Application.ScreenUpdating = 0
        
        For i = 2 To sh.Range("A" & Rows.Count).End(xlUp).Row
            ws.Copy After:=sh
            ActiveSheet.Name = sh.Range("A" & i).Value
        Next i
    End Sub
    Just a couple of details, in the For cycle, you should put the sheet sh. only if you do not execute the macro from the sheet "Sheets Insert"


    Although it is not important, also the reference of ws, to apprave that you established the object.
    Regards Dante Amor

  4. #4
    New Member
    Join Date
    Feb 2015
    Posts
    35
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Duplicate template based on refreshed list

    Thanks Dante, worked great!

  5. #5
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,310
    Post Thanks / Like
    Mentioned
    50 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Duplicate template based on refreshed list

    Quote Originally Posted by JAnders View Post
    Thanks Dante, worked great!
    Im glad to help you. Thanks for the feedback.
    Regards Dante Amor

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •