Results 1 to 4 of 4

Error handling on InputBox entry when nothing is entered

Threaded View

  1. #1
    Registered User
    Join Date
    02-09-2010
    Location
    Seaton Delaval, Northumberland
    MS-Off Ver
    Office 365
    Posts
    31

    Question Error handling on InputBox entry when nothing is entered

    Hi all,

    I have some code that creates a new sheet and names it what ever the user enters into an InputBox.

    It works when they enter a name.
    It works when they click 'Cancel'.
    But it returns a “Run-time error ‘9’@: Subscript out of range” error if you click OK without entering anything in the InputBox.

    How do I stop it/loop it back after the ‘If Response = "" Then” section because it’s trying to create a sheet without a name!

    I can't get my head around it! I'm trying to teach myself VBA but it's going very slowly.

    Sub AddNewSheet()
    
        Sheets("Template").Visible = True
        Sheets("Template").Copy After:=Worksheets(Worksheets.Count)
        Sheets("Template").Visible = False
        Response = Application.InputBox("Enter the technician's name:")
        
        If Response = False Then
            Application.DisplayAlerts = False
            Sheets("Template (2)").Delete
            Sheets("Main").Select
        End If
        
        If Response = "" Then
            MsgBox "Please enter a technician's name."
            Application.DisplayAlerts = False
            Sheets("Template (2)").Delete
            Sheets("Main").Select
        End If
               
        If Response <> False Then
            Sheets("Template (2)").Name = Response
        End If
    
    End Sub
    Last edited by Kungfauxn00b; 03-24-2011 at 04:45 AM.
    Dave (Excel n00b)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1