G
GregR
I have this code, which adds sheets to a workbook based on a named
range. It renames the sheets to the name in the range, but errors on
the second name change because it already exists. How do I get he
macro to rename sheets based on the names in the named list. TIA
Sub AddRangeOfSheets()
Dim c As Range
For Each c In Sheets("sheet1").Range("SList")
If Not IsEmpty(c) Then
CreateSheet (c.Value)
End If
Next c
End Sub
Sub CreateSheet(ShName As String)
Dim CreateSheet As Worksheet
On Error GoTo errh
Set CreateSheet = ActiveWorkbook.Worksheets(ShName)
Exit Sub
errh:
Set CreateSheet = ActiveWorkbook.Worksheets.Add
CreateSheet.Name = ShName
End Sub
Thanks, Greg
range. It renames the sheets to the name in the range, but errors on
the second name change because it already exists. How do I get he
macro to rename sheets based on the names in the named list. TIA
Sub AddRangeOfSheets()
Dim c As Range
For Each c In Sheets("sheet1").Range("SList")
If Not IsEmpty(c) Then
CreateSheet (c.Value)
End If
Next c
End Sub
Sub CreateSheet(ShName As String)
Dim CreateSheet As Worksheet
On Error GoTo errh
Set CreateSheet = ActiveWorkbook.Worksheets(ShName)
Exit Sub
errh:
Set CreateSheet = ActiveWorkbook.Worksheets.Add
CreateSheet.Name = ShName
End Sub
Thanks, Greg