+ Reply to Thread
Results 1 to 14 of 14

A blank input to a InputBox (method) runs the alert of typing formula in a cell with error

  1. #1
    Registered User
    Join Date
    12-21-2020
    Location
    Santa Oliva
    MS-Off Ver
    Excel 2003, Excel 2007, Excel(Mac) 2011
    Posts
    11

    Unhappy A blank input to a InputBox (method) runs the alert of typing formula in a cell with error

    Hi, everybody,
    I want a very simple InputBox, but I want it to be with the InputBox method, to validate the input as numeric and evaluate easyly when it is cancelled by the user. By the way, then I'll do one more validation to the input value, no problem with that.

    When I clic OK with nothing in the entry field of the InputBox dialog, I get the same alert you get when you type a formula which contains errors in a cell:
    "The formula you typed contains an error.
    • For information about fixing...
    • To get assistance in...
    • If you are not trying..."


    It supposed that a blanck entry will yield a 0-length string, perhaps a vbNullString. The variable getting the value is variant. Parameter "Type" is 1.
    I made trials with/without default value. And don't want to go to the InputBox function.
    Why the hell Excel-VBA thinks anyone is typing anything into a cell?

    Attached a sample to reproduce this behavior. Wondering to know from you guys what stupid mistake I'm doing.
    Thank you.
    Attached Files Attached Files
    Last edited by Pete u'Line; 06-05-2023 at 12:58 PM. Reason: typos, incorrect English: "I'm want" changed to "I want"

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: A blank input to a InputBox (method) runs the alert of typing formula in a cell with e

    Hi, what you want (need actually) is this link https://excelmacromastery.com/vba-inputbox/
    Read and learn
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    12-21-2020
    Location
    Santa Oliva
    MS-Off Ver
    Excel 2003, Excel 2007, Excel(Mac) 2011
    Posts
    11

    Re: A blank input to a InputBox (method) runs the alert of typing formula in a cell with e

    Thank you, Keebellah.
    I hope you tried the attached sample and understood better with it than with my words.
    In fact I've red that article and it's still open in my browser. I'll go to it with more attention and will tell what find about this point.

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: A blank input to a InputBox (method) runs the alert of typing formula in a cell with e

    The fact you get the 'crazy message' is very simple. The InputBox expects a numeric value and the default answer for Excel when that is not entered is what you will get.

    YOU are the one that bwnats to determine what is enetered so do NOT force the type entry if you want other entries or wanht to 'trap' OK .

    The check of the entry must be dona AFTER the Inputbox

    You test the entry result AFTER you do anything with the InoputBox

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: A blank input to a InputBox (method) runs the alert of typing formula in a cell with e

    Try this file

    Right click the cell to open inoutbox
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,966

    Re: A blank input to a InputBox (method) runs the alert of typing formula in a cell with e

    To get rid of the formula error, change the Type to a string and check for a number in the code.

    Please Login or Register  to view this content.

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: A blank input to a InputBox (method) runs the alert of typing formula in a cell with e

    Minor correction applied
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    12-21-2020
    Location
    Santa Oliva
    MS-Off Ver
    Excel 2003, Excel 2007, Excel(Mac) 2011
    Posts
    11

    Re: A blank input to a InputBox (method) runs the alert of typing formula in a cell with e

    Quote Originally Posted by Keebellah View Post
    ... The InputBox expects a numeric value and the default answer for Excel when that is not entered is what you will get.

    ... do NOT force the type entry if you want other entries...
    Keebellah, firstable, I must say that I want to learn the benefits of using InputBox method instead of the function, just because it exists. And the "Type" parameter is the promised diamond shinning at the top of the mountain.

    Despite the fact that "Type:=1" makes InputBox to expect a numeric value, entries like "abc", " abc", "/" (strings) kindly tell the user that "Number is not valid" and gives him/her a new opportunity, without extra validation code:


    In the other hand, a "blank OK" (also a string, null or empty) doesn't produce the same nice effect, nor one space or a string of spaces.



    I don't want other entries than numeric ones, but just prevent the possible user's actions. If user clics "OK" accidentaly when nothing is entered, he/she will expect either a new opportunity or a cancellation effect. Even an erroneous validation of "" as a zero could be acceptable by a forbearing user.

    What is not understandable is "to accuse" the user of misstyping a formula in a cell, a user that perhaps hasn't never put an equal character "=" in a cell in his whole life:


    This (certainly crazy) alert is untrappable, unlike errors, to be handled. Yes, I can disable displaying alerts. If I do that, then I lose the kind "Numer is not valid" message when entering strings and I must substitute it with a msgbox with similar text and code to show the box again.

    So, the shinning diamond still brights far.
    Last edited by Pete u'Line; 06-06-2023 at 01:57 AM.

  9. #9
    Registered User
    Join Date
    12-21-2020
    Location
    Santa Oliva
    MS-Off Ver
    Excel 2003, Excel 2007, Excel(Mac) 2011
    Posts
    11

    Re: A blank input to a InputBox (method) runs the alert of typing formula in a cell with e

    Quote Originally Posted by Keebellah View Post
    Try this file
    Right click the cell to open inoutbox
    I should better not put anything in any sheet, to ask my question, but you made a funny game with my named range! It makes the "impossible" message to appear! ("Shouldn't be never printed")
    And let me say, I liked very much this dynamic msgbox, telling the left opportunities of entering the value.
    I see that you get rid of the "Type" parameter. Then InputBox yields a handleable string, an empty or null one, i. e..
    Last edited by Pete u'Line; 06-06-2023 at 01:46 AM.

  10. #10
    Registered User
    Join Date
    12-21-2020
    Location
    Santa Oliva
    MS-Off Ver
    Excel 2003, Excel 2007, Excel(Mac) 2011
    Posts
    11

    Re: A blank input to a InputBox (method) runs the alert of typing formula in a cell with e

    Quote Originally Posted by ByteMarks View Post
    To get rid of the formula error, change the Type to a string and check for a number in the code.
    Thank you very much, ByteMarks.
    Your solution is very good. With Type:=2, blank-OK returns (0-lenght)-string, and you manage to validate it the same as it was a zero in my secondary validation (9<x<21).

    Still curious about what a blank-OK (also “ “-OK) returns with Type:=1 (for sure, not a 0-length string), and how it triggers that non-sense alert.

  11. #11
    Registered User
    Join Date
    12-21-2020
    Location
    Santa Oliva
    MS-Off Ver
    Excel 2003, Excel 2007, Excel(Mac) 2011
    Posts
    11

    Re: A blank input to a InputBox (method) runs the alert of typing formula in a cell with e

    Quote Originally Posted by Keebellah View Post
    Minor correction applied
    Another wonderful sheet event!
    Thank you for your clever suggestions, Keebellah!

  12. #12
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: A blank input to a InputBox (method) runs the alert of typing formula in a cell with e

    And now this should do the trick, you can enter anything in the cell o the sheet and if it's invalid the userform will appear
    I attached a version for 2007 and up so if nobody uses older versions you can use this one (xlsm)
    Or else you may stick to the xls but you will get the compatability question when saving

    BTW: I implemente ByteMark's solution since it did thetrick
    Last edited by Keebellah; 06-06-2023 at 02:41 AM.

  13. #13
    Registered User
    Join Date
    12-21-2020
    Location
    Santa Oliva
    MS-Off Ver
    Excel 2003, Excel 2007, Excel(Mac) 2011
    Posts
    11

    Re: A blank input to a InputBox (method) runs the alert of typing formula in a cell with e

    So, I've got the best of two answerers in one
    Very good job, Hans. I appreciate your help, proposals and tricks, beyond the asked question.
    I'm already convinced of not to use "Type:=1", so a bit frustrated for this.

  14. #14
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: A blank input to a InputBox (method) runs the alert of typing formula in a cell with e

    The Type:=1 is okay but you seem to dislike the answer Excel shows as default if the entry is not numeric.
    You can avoid all this if you use a simple userform where you can enter only one field with numbers .
    Attached Files Attached Files
    Last edited by Keebellah; 06-06-2023 at 04:00 PM.

+ 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. Disable Typing/Paste/editing & Double click on locked cell without notification alert
    By abhinavbinkar in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-19-2018, 05:14 AM
  2. [SOLVED] Clear Text Box after Input Error Alert
    By azheuer in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-18-2018, 11:40 PM
  3. [SOLVED] inputbox to select cells instead of typing cell locations
    By miyachow in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2013, 09:20 AM
  4. Cancelling an inputbox if blank input or cancel button is pressed
    By kathhying in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-01-2011, 12:07 PM
  5. Retain the state of an inputbox's default input for successive runs
    By MCCCLXXXV in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-05-2011, 10:02 AM
  6. [SOLVED] Formula expected end of statement error, typing formula into cell as part of VBA macro
    By DavidGMullins@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2006, 03:05 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

Tags for this Thread

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