I'm trying to run a macro to create (copy a template) a sheet, and then name it according to data in a table.
Here's my code:
Sub CreateSheetsFromInfo()
Dim MyCell As Range, MyRange As Range
Set MyRange = Sheets("Info").Range("D2")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
For Each MyCell In MyRange
Sheets(4).Copy After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = MyCell.Value
Next MyCell
End Sub
It works as needed, but only on first use. If new info is added to the range, it will not add new sheets for them, as it tries to create them all again and discovers duplicate names. How can I get it to skip past existing sheets?
Also, I would like for the template sheet to be hidden, but the new sheets to be shown. If I currently hide the template, it (obviously) hides the copies, but also has trouble renaming them appropriately.
Thanks!
Here's my code:
Sub CreateSheetsFromInfo()
Dim MyCell As Range, MyRange As Range
Set MyRange = Sheets("Info").Range("D2")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
For Each MyCell In MyRange
Sheets(4).Copy After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = MyCell.Value
Next MyCell
End Sub
It works as needed, but only on first use. If new info is added to the range, it will not add new sheets for them, as it tries to create them all again and discovers duplicate names. How can I get it to skip past existing sheets?
Also, I would like for the template sheet to be hidden, but the new sheets to be shown. If I currently hide the template, it (obviously) hides the copies, but also has trouble renaming them appropriately.
Thanks!