+ Reply to Thread
Results 1 to 7 of 7

Application.InputBox Throwing Type Mismatch Error

  1. #1
    Registered User
    Join Date
    12-30-2010
    Location
    New Haven, Ct
    MS-Off Ver
    Excel 2016
    Posts
    41

    Application.InputBox Throwing Type Mismatch Error

    Hello all!

    I'm having an issue with application.inputbox throwing a type mismatch error. I'm currently using the application.inputbox to prompt the user to name a new worksheet. I'm using the application.inputbox method because I am able to capture the cancel button click by testing whether the value returned is "false".

    The issue that I'm running into is that when I input a string of numbers everything passes through just fine. If I click "cancel" then everything works fine. If I input a single letter character into the inputbox I get a type mismatch error. For the life of me I am unable to figure out why it's doing this.

    Any help or suggestions would be greatly appreciated.

    Here is the code that I'm using:
    Please Login or Register  to view this content.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Application.InputBox Throwing Type Mismatch Error

    Your first input box correctly identifies the data type as string, Type:=2.
    The second input box does not specify the data type so it uses default which is String.
    Both should produce error 13 if you enter numbers because you have declared SheetName as String in your declarations.
    The InputBox function will produce only string data. The Applicacation.InputBox Method allows the user to specify what data type they want the associated variable to hold.
    Last edited by JLGWhiz; 02-15-2019 at 03:43 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    12-30-2010
    Location
    New Haven, Ct
    MS-Off Ver
    Excel 2016
    Posts
    41

    Re: Application.InputBox Throwing Type Mismatch Error

    Thanks so much for your reply!

    Quote Originally Posted by JLGWhiz View Post
    Your first input box correctly identifies the data type as string, Type:=2.
    The second input box does not specify the data type so it uses default which is String.
    When tested, specifying the data type as string didn't make any difference, I still received the same error 13.

    Quote Originally Posted by JLGWhiz View Post
    Both should produce error 13 if you enter numbers because you have declared SheetName as String in your declarations. The InputBox function will produce only string data.
    It actually worked opposite to what you've described. When I pass "123456789" as a value- no problem. When I pass "Another Sheet"- I get error 13.

    When adding a watch to the SheetName variable, both "123456789" and "Another Sheet" cause the variable to become type String.

  4. #4
    Registered User
    Join Date
    12-30-2010
    Location
    New Haven, Ct
    MS-Off Ver
    Excel 2016
    Posts
    41

    Re: Application.InputBox Throwing Type Mismatch Error

    I got it working by formatting the SheetName variable with CStr(SheetName). While this works, there is one issue: if the user attempts to name their worksheet "false", the sub will terminate because it thinks the cancel button on the inputbox was clicked.

    Please Login or Register  to view this content.
    This will work in the meantime however if anyone has a better idea I'd love to hear it. Also, if anyone knows why I was getting an error 13 with my original code, please let me know.

  5. #5
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Application.InputBox Throwing Type Mismatch Error

    Deleted by author.
    Last edited by JLGWhiz; 02-15-2019 at 08:37 PM.

  6. #6
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Application.InputBox Throwing Type Mismatch Error

    If you have people who name worksheets "True" or "False" they should not be working there very long.
    glad you god it working and thanks for the feedback.
    Regards, JLG

  7. #7
    Registered User
    Join Date
    12-30-2010
    Location
    New Haven, Ct
    MS-Off Ver
    Excel 2016
    Posts
    41
    Quote Originally Posted by JLGWhiz View Post
    If you have people who name worksheets "True" or "False" they should not be working there very long.
    I’m with you. I think that the saying “make something idiot-proof and they’ll just find a way to build a bigger idiot” came from my company.

+ 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. [SOLVED] SUMPRODUCT throwing RunTime Error 13 - Type mismatch
    By Ochimus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-03-2018, 11:08 PM
  2. Application.Transpose(junk_array) .....gives type mismatch error
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-06-2013, 08:22 AM
  3. 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
  4. Application.GetOpenFilename Type mismatch error
    By brl8 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-03-2011, 04:56 PM
  5. Type Mismatch error on InputBox
    By h_aesa1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2009, 09:21 AM
  6. Application.Vlookup Type Mismatch Error
    By ssjody in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2006, 05:24 PM
  7. [SOLVED] Type Mismatch Error when using InputBox Method
    By Anolan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-22-2005, 03:40 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