+ Reply to Thread
Results 1 to 4 of 4

Cancel my Inputbox

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Cancel my Inputbox

    I have a simple Inputbox macro that creates a new sheet called whatever is unput. When hitting the cancel button though I get an error (object defined 1004 job)

    How do I solve this?

    Sub NewS()
    
    Dim Sheetname As String
    Worksheets("Template").Visible = True
    Sheetname = InputBox("Please enter new sheet name, Use format MMM YYYY")
    ActiveWorkbook.Sheets("Template").Copy after:=Sheets(Sheets.Count)
    ActiveSheet.Name = Sheetname
    ActiveSheet.Range("A1").Value = Sheetname
    MsgBox "Dont forget to fill in Budget and Forecast values"
    Worksheets("Template").Visible = False
    End Sub

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Cancel my Inputbox

    change so
    If Sheetname = "" Then Exit Sub
    ActiveSheet.Name = Sheetname
    Last edited by patel45; 08-21-2012 at 10:50 AM.

  3. #3
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Cancel my Inputbox

    Does the following do what you need?
    Sheetname = InputBox("Please enter new sheet name, Use format MMM YYYY")
    If Sheetname = vbNullString Then
        Exit Sub
    End If
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  4. #4
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Cancel my Inputbox

    works brilliantly thanks!

    ---------- Post added at 04:05 PM ---------- Previous post was at 04:03 PM ----------

    also is there a way to force the input to be MMM YYYY if there is anything else it comes up with a message saying "Wrong input" or something>?

+ Reply to Thread

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