VBA to copy template sheet and rename based on items in list on master sheet

KjKLady

New Member
Joined
Dec 12, 2019
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
Help? I'm trying to set a macro that will reference a list within a "SiteMaster" worksheet (starting from C6) and create a new copy of a "LibraryTemplate" worksheet for each item in that list, then rename it to match how it is identified in the list. I also should note that the "SiteMaster" sheet will be named with the following pattern: "SiteMaster - Actual Site Name" - so I believe the reference to this master sheet will require a Like statement or wildcard function?

**Bonus ask - would also like this to check if a sheet name already exists, if it does, skip and do not copy/create a new worksheet.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi @KjKLady, welcome to the board!

Try this

VBA Code:
Sub copy_template()
  Dim sh As Worksheet, sh1 As Worksheet, c As Range
  Application.ScreenUpdating = False
  For Each sh In Sheets
    If sh.Name Like "SiteMaster*" Then
      Set sh1 = sh
      Exit For
    End If
  Next
 
  If sh1 Is Nothing Then
    MsgBox "The sheet does not exist: SiteMaster"
    Exit Sub
  End If
 
  For Each c In sh1.Range("C6", sh1.Range("C" & Rows.Count).End(xlUp))
    If Not Evaluate("ISREF('" & c.Value & "'!A1)") Then
      Sheets("LibraryTemplate").Copy after:=Sheets(Sheets.Count)
      ActiveSheet.Name = c.Value
    End If
  Next
 
  MsgBox "Done"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,841
Members
449,051
Latest member
excelquestion515

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