I have a code to copy and name worksheets, this code warns me when I have a worksheet with the same name and request another name, but I can make it request this only once before copying a worksheet, I would like it I got the name wrong again he would ask until the name was accepted before copying the worksheet. But I'm not able to do the loop, and whenever he asks the second time, he already copies the worksheet even without having typed the name yet.
Sub CopySheet()
Dim i As Integer, x As Integer
Dim shtname As String
shtname = InputBox("Worksheet Name?", "Name?")
If StrPtr(shtname) = 0 Then
Exit Sub
Else
On Error GoTo errhandler
End If
errhandler:
shtname = InputBox("Name taken!", "Name?")
If StrPtr(shtname) = 0 Then
Exit Sub
Else
On Error GoTo errhandler
End If
Sheets("MODELO").Copy Before:=Sheets("CC")
ActiveSheet.Name = shtname
End Sub
