+ Reply to Thread
Results 1 to 6 of 6

handling blank input box

Hybrid View

daviddoria handling blank input box 12-27-2008, 12:27 PM
VBA Noob Your post does not comply... 12-27-2008, 12:35 PM
daviddoria I fixed it, but generally 1-3... 12-27-2008, 12:57 PM
shg You can use either, just be... 12-27-2008, 02:40 PM
Leith Ross Hello Dave, Just for... 12-27-2008, 07:01 PM
daviddoria ah ok, i'll keep that in... 12-27-2008, 09:55 PM
  1. #1
    Registered User
    Join Date
    12-23-2008
    Location
    USA
    Posts
    60

    handling blank input box

    If I do this:
    salesgoal = Application.InputBox("What is the sales goal for the month?", Title:="Holidays", Type:=1)
    If the user clicks "OK" without entering anything, it produces an error. I tried handling it with
    If salesgoal = vbNullString Then
        Exit Sub
    End If
    but it doesn't get there, excel throws an error before it runs that "if null" line.

    Is there a way to fix this?

    Thanks,
    Dave
    Last edited by daviddoria; 12-27-2008 at 09:55 PM. Reason: fixed code tags

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    12-23-2008
    Location
    USA
    Posts
    60
    I fixed it, but generally 1-3 line things aren't any easier to read with code tags, are they?

    Also, the
    type:=1
    was forcing it to check if the value was numeric - is the idea just not to use the built in error checking, simply read the value as a string, and convert it to a numeric value when needed?

    Dave

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    You can use either, just be consistent.

    If you use the InputBox method (i.e., Application.InputBox) with type = 1, Excel will force you to input a number or numeric formula, the method will always return a number, and you can receive the result in a numeric variable.

    If you just use InputBox, you should return the result to string variable and do whatever error checking is appropriate to your application. If the user enters a formula, you need to evaluate it yourself.

    A numeric variable can never be vbNullString. And if you want to test if a string variable is a null string, you should use the Len function -- it's faster.

    I fixed it, but generally 1-3 line things aren't any easier to read with code tags, are they?
    It is for us.
    Last edited by shg; 12-27-2008 at 02:43 PM.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Dave,

    Just for future reference, vbNullString and an empty string "" are not the same thing. vbNullString is a special string that contains Chr$(0). This is useful when writing code with API functions, but should not be used to test if a string is empty (no characters in the string).

    Sincerely,
    Leith Ross

  6. #6
    Registered User
    Join Date
    12-23-2008
    Location
    USA
    Posts
    60
    ah ok, i'll keep that in mind, thanks

+ 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