adutchbrew
New Member
- Joined
- Jan 31, 2018
- Messages
- 3
I am new to vba. Trying to write code to generate copies from a template worksheet and name the copies from a range in primary worksheet. The ws tabs should be in a date format. So far I was able to generate the copies from the template and it makes the amount of copies in the range, but instead of the ws tabs showing as the date, they are named Template (2) to Template.
Here is the code I wrote that works:
Sub DuplicateAndRenameSheets()
Dim wsMaster As Worksheet
Dim wsTemp As Worksheet
Dim shNames As Range
Dim Nm As Range
Application.ScreenUpdating = 0
With ThisWorkbook
Set wsTemp = .Sheets("Template")
Set wsMaster = .Sheets("Master")
Set shNames = wsMaster.Range("A4:A10") 'The range is formatted as eg Jan 28, Jan 29 etc.
For Each Nm In shNames
wsTemp.Copy After:=.Sheets(.Sheets.Count)
' Nm.Name = Format(Date,"mmmdd") This is one of the code lines I tried but doesn't work
Next Nm
End With
Application.ScreenUpdating = 1
End Sub
Any help is much appreciated
Here is the code I wrote that works:
Sub DuplicateAndRenameSheets()
Dim wsMaster As Worksheet
Dim wsTemp As Worksheet
Dim shNames As Range
Dim Nm As Range
Application.ScreenUpdating = 0
With ThisWorkbook
Set wsTemp = .Sheets("Template")
Set wsMaster = .Sheets("Master")
Set shNames = wsMaster.Range("A4:A10") 'The range is formatted as eg Jan 28, Jan 29 etc.
For Each Nm In shNames
wsTemp.Copy After:=.Sheets(.Sheets.Count)
' Nm.Name = Format(Date,"mmmdd") This is one of the code lines I tried but doesn't work
Next Nm
End With
Application.ScreenUpdating = 1
End Sub
Any help is much appreciated