Run-time error "1004' Application-defined or object-defined error with input box

32 Views Asked by At

I have my input box code set up the way I want, but when someone clicks either the "X" or "Cancel" I want it to just stop running the macro. Instead when someone clicks that the error "Run-time error '1004' Application-defined or object-defined error" pops up.

This is my code:

Dim Newname As String
 Newname = InputBox("Name for new worksheet?")
 If Newname <> "" Then
    Sheets("PumpTag#").Copy Before:=Sheets("PumpTag#")
    ActiveSheet.Name = Newname
    
 End If

I tried putting an ElseIf (StrPtr(Newname)= 0) Then End Sub before the End If but that came back with an error of blocking an If statement with End If

0

There are 0 best solutions below