Searching will get you a lot of answers, especially on Stackoverflow. Here are some examples of what I searched for, and maybe it'll help you.
I know an answer has been posted, but since I had something already, and it's slightly different, thought I'd post it anyways since it has some extra features which you might be able to glean from. It includes:
- Error checking (in case a sheet of the same name exists)
- The sub routine as a called in a separate routine while passing variables
Give it try and let me know what you think.
Function SheetExists(shtName As String, Optional wb As Workbook) As Boolean
'Created by Tim Williams from Stackoverflow.com
'https://stackoverflow.com/questions/6688131/excel-vba-how-to-test-if-sheet-exists
Dim sht As Worksheet
If wb Is Nothing Then Set wb = ThisWorkbook
On Error Resume Next
Set sht = wb.Sheets(shtName)
On Error GoTo 0
SheetExists = Not sht Is Nothing
End Function
Sub CreateSummarySheets(SummaryWS As Worksheet, TemplateWS As Worksheet)
Dim newWS As Worksheet
Dim rCell As Range
Dim lastRow As Long
Dim answer As Long
lastRow = SummaryWS.Cells(Rows.Count, "A").End(xlUp).Row
For Each rCell In SummaryWS.Range("$A$1:$A$" & lastRow)
'Add copy of template
TemplateWS.Copy After:=Sheets(Sheets.Count)
Set newWS = Sheets(Sheets.Count)
'Sheet exists error checking
answer = 1
If SheetExists(newWS.Name) = False Then
answer = vbNo
answer = MsgBox("Sheet with the name " & rCell.Value & " already exists. Delete it?", vbYesNo, rCell.Value & " Sheet Exists")
End If
If answer = vbYes Then
Sheets(rCell.Value).Delete
End If
If answer = 1 Or answer = vbYes Then
newWS.Name = rCell.Value
End If
'Populate newWS's cell A1
newWS.Cells(1, "A") = rCell.Value
'Add Hyperlink from summary to newWS
newWS.Hyperlinks.Add Anchor:=rCell, Address:="", _
SubAddress:="'" & newWS.Name & "'" & "!A1", TextToDisplay:=newWS.Name
Next rCell
End Sub
Sub test()
Dim s_ws As Worksheet
Set s_ws = Sheets("Summary")
'Two ways to run this function
Call CreateSummarySheets(s_ws, Sheets("Template"))
End Sub