0

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

Laurel
  • 5,965
  • 14
  • 31
  • 57
  • 3
    Are you sure the error is in the part of the code you posted? `If Len(Newname) = 0 Then Exit Sub` right after the `Inputbox` line call should do it. – Tim Williams Apr 12 '23 at 14:51

0 Answers0