New Member
December 3, 2018
Please, I need your help.
in range A1:A50 in sheet "name" i have the names of new sheets i would like to add.
my code below to add those sheets is working well, however, if i start the code again he also add worksheets named: name1, name2, name3 etc..
please help to solve this.
With many thanks.
Sub test()
On Error Resume Next
Sheets("naam").Select
Dim template As Range
For Each template In Range("A1:A5")
If template.Offset(0, 0).Value <> "" Then
Dim tabblad As Worksheet
Set tabblad = ThisWorkbook.Worksheets("naam")
tabblad.Copy ThisWorkbook.Sheets(Sheets.Count)
With ThisWorkbook
ActiveSheet.Name = template.Offset(0, 0).Value
End With
Else
Exit Sub
End If
Next
end sub
Trusted Members
Moderators
November 1, 2018
You could check to see if the sheets already exist like this:
Sub test()
Dim template As Range
Dim tabblad As Worksheet
Set tabblad = ThisWorkbook.Worksheets("naam")
For Each template In Sheets("naam").Range("A1:A5")
If template.Value <> "" Then
If Not Application.Evaluate("ISREF('" & template.Value & "'!A1)") Then
tabblad.Copy ThisWorkbook.Sheets(Sheets.Count)
ActiveSheet.Name = template.Value
End If
Else
Exit Sub
End If
Next
End Sub
Answers Post
1 Guest(s)