Duplicate template based on refreshed list

JAnders

New Member
Joined
Feb 27, 2015
Messages
37
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!
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

JAnders

New Member
Joined
Feb 27, 2015
Messages
37
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
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,202
Office Version
2007
Platform
Windows
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 [COLOR=#ff0000]sh.[/COLOR]Range("A" & Rows.Count).End(xlUp).Row
        [COLOR=#ff0000]ws[/COLOR].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.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,457
Messages
5,487,004
Members
407,575
Latest member
calc

This Week's Hot Topics

Top