jondallimore
Board Regular
- Joined
- Apr 26, 2012
- Messages
- 136
Hello,
I have the code below which copies the Template worksheet depending on a value in column A (rnglist).
Can anyone think of a way to adapt it so that I could use several template sheets?
I want to have several template sheets called Mon1, Tue1, Wed1, Thurs1, and Fri1, and the same; Mon2, Tue2 etc.
I then want the code to select which template to copy based on values in column B - which will contain eg, "Mon1", and to use the values in Column A as the name for the sheet.
If anyone can help, I would be incredibly grateful.
Many thanks
Jon
I have the code below which copies the Template worksheet depending on a value in column A (rnglist).
Can anyone think of a way to adapt it so that I could use several template sheets?
I want to have several template sheets called Mon1, Tue1, Wed1, Thurs1, and Fri1, and the same; Mon2, Tue2 etc.
I then want the code to select which template to copy based on values in column B - which will contain eg, "Mon1", and to use the values in Column A as the name for the sheet.
If anyone can help, I would be incredibly grateful.
Many thanks
Jon
Code:
Doit: Application.ScreenUpdating = False
For Each cell In rnglist
If cell.Value <> "" Then
On Error Resume Next
'test if worksheet exists
If Len(Worksheets(cell.Value).name) = 0 Then
On Error GoTo 0
'copy worksheet named "Template"
Worksheets("Template").Copy After:=Worksheets(Worksheets.Count)
ActiveSheet.name = cell.Value 'name new sheet
'Create hyperlink
Let x = "'" & cell.Value & "'!A1"
cell.Parent.hyperlinks.Add Anchor:=cell, _
Address:="", _
SubAddress:=x, _
TextToDisplay:=cell.Value
End If
On Error GoTo 0
End If
Next cell
CommandButton1.Parent.Activate 'go back to the source worksheet
'Delete "Other" Sheets not on the list
Application.DisplayAlerts = False
For Each ws In Worksheets
'Keep these non-list sheets
If InStr("|Navigation|Template|Instructions|", "|" & ws.name & "|") = 0 Then
'Test if each sheet is on the list
If WorksheetFunction.CountIf(rnglist, ws.name) = 0 Then ws.Delete
End If
Next ws