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!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top