+ Reply to Thread
Results 1 to 3 of 3

Error when hitting cancel on Application.InputBox

  1. #1
    Registered User
    Join Date
    06-15-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Error when hitting cancel on Application.InputBox

    Dear forum,

    When I hit cancel on an InputBox, I receive the error message:

    Run-time error '13':
    Type mismatch and it highlights

    If v then as the suspect code.

    The full code I am using is below - can anyone help me with the obvious mistake, I'm not even a begginer at this stuff!

    Thanks for any advice.

    Please Login or Register  to view this content.
    Sub Opening_Weekly_Stock(ByVal control As IRibbonControl)
    Dim sName As String
    Dim sPic As String


    sPic = Application.InputBox("Enter the Week To be Copied:", Title:="Source Week Title", Type:=2)
    If sPic = "" Then Exit Sub

    Dim v: v = Evaluate("ISREF(" & sPic & "!A1)")
    If v Then
    sName = Application.InputBox("Enter the new week name:", Title:="New Week Title", Type:=2)
    If sName = "" Then Exit Sub
    Sheets(sPic).copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = sName
    Else
    MsgBox "The Worksheet " & sPic & " cannot be found."
    End If
    Call Enter_Opening_Stock
    Call Remove_Zero_Stock
    End Sub
    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Error when hitting cancel on Application.InputBox

    If you hit Cancel sPic will be 'False'.

    Unless you have a sheet naed 'False' v will be Error 2015 (or something like that).

    Even if you didn't press Cancel but entered something that wasn't the name of a sheet v would be an error.

    So you need to check if v is an error which you can do with IsError.

    Change If v Then to this.
    Please Login or Register  to view this content.
    PS Please use code tags when posting code.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    06-15-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Error when hitting cancel on Application.InputBox

    Norie,

    Many thanks - much appreciated. Sorry for missing the tags, thought I had done it.

    Cheers
    Dean

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Using Application.Inputbox.........getting type mismatch error
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-21-2011, 07:33 AM
  2. Inputbox cancel button error.
    By abhay_547 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-05-2010, 06:27 AM
  3. Screen positioning inputbox that is set as Application.InputBox
    By vdongen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-06-2010, 07:59 AM
  4. Error Prevention Application.InputBox
    By AccountantCost in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-07-2009, 06:43 PM
  5. Cancel on INPUTBOX macro causes error
    By Barb Reinhardt in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-21-2006, 07:35 PM

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