A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Use a VBA macro that copies the template sheet with Copy After:=..., names each new sheet from Data File!C4:C15, places each copy immediately after the previous one, and writes a hyperlinked list in Data File starting at F4.
Sub CopyAndListSheets()
Dim wsData As Worksheet
Dim wsTemplate As Worksheet
Dim wsNew As Worksheet
Dim copyAfter As Worksheet
Dim cell As Range
Dim outRow As Long
Dim newName As String
Set wsData = ThisWorkbook.Worksheets("Data File")
Set wsTemplate = ThisWorkbook.Worksheets("Master Template_Collectives")
Set copyAfter = wsTemplate
outRow = 4
For Each cell In wsData.Range("C4:C15")
If Trim(cell.Value) <> "" Then
newName = CStr(cell.Value)
wsTemplate.Copy After:=copyAfter
Set wsNew = ActiveSheet
wsNew.Name = newName
Set copyAfter = wsNew
wsData.Cells(outRow, "F").Value = newName
wsData.Hyperlinks.Add _
Anchor:=wsData.Cells(outRow, "F"), _
Address:="", _
SubAddress:="'" & newName & "'!A1", _
TextToDisplay:=newName
outRow = outRow + 1
End If
Next cell
End Sub
What this does:
- Reads sheet names from
Data FilecellsC4:C15. - Copies
Master Template_Collectivesonce for each nonblank cell. - Places each new sheet after the previous copied sheet, so the order matches the list.
- Leaves existing sheets untouched.
- Writes the new sheet names to
Data File!F4:F.... - Creates hyperlinks in column
Fto each new sheet.
Notes:
- If a name in
C4:C15already exists as a worksheet name, renaming the copied sheet will fail. - If a name is invalid for Excel sheet names, renaming will fail.
- This macro does not delete any existing sheets.
The worksheet copy behavior is based on Excel VBA Copy After:=..., which places the copied sheet after the specified sheet.