+ Reply to Thread
Results 1 to 9 of 9

Return an error if text is inputted rather than a number

  1. #1
    Registered User
    Join Date
    10-15-2014
    Location
    DC
    MS-Off Ver
    2010 (work) / 2013 (home)
    Posts
    15

    Return an error if text is inputted rather than a number

    I wish my problem was as black and white as that, but there's a bit of grey area which is why I'm having trouble...

    This is part of the code I have for a button I have on one of my spreadsheets. I ask the user to input a time. It can be 5 digits (hh:mm) AND must include a colon in the third place/digit, OR it can be blank.

    I am trying to make this AS dummy proof as a I can for the folks who'll be using the tool it's attached to. So I am having trouble with integrating how to add code to make the error message box pop-up if the user inputs text (for ex. as:df). Any help would be greatly appreciated!



    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Return an error if text is inputted rather than a number

    Hi

    I spent a couple of hours a few weeks ago trying to figure out how to make date entry idiot proof.

    My result is quite neat.

    I mill modify it to cope with your times.

    This is a userform text box right?
    Last edited by mehmetcik; 10-28-2014 at 03:50 PM.

  3. #3
    Registered User
    Join Date
    10-15-2014
    Location
    DC
    MS-Off Ver
    2010 (work) / 2013 (home)
    Posts
    15

    Re: Return an error if text is inputted rather than a number

    Quote Originally Posted by mehmetcik View Post
    Hi

    I spent a couple of hours a few weeks ago trying to figure out how to make date entry idiot proof.

    My result is quite neat.

    I mill modify it to cope with your times.

    This is a userform text box right?

    Yes it is a userform text box. Thank you!
    Last edited by BladeAP; 10-28-2014 at 04:21 PM.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Return an error if text is inputted rather than a number

    Ok try this for me.

    I have an idea on how to improve it. but let me know what you think of it so far.
    Attached Files Attached Files
    Last edited by mehmetcik; 10-28-2014 at 04:36 PM. Reason: Revised Userform

  5. #5
    Registered User
    Join Date
    10-15-2014
    Location
    DC
    MS-Off Ver
    2010 (work) / 2013 (home)
    Posts
    15

    Re: Return an error if text is inputted rather than a number

    Looks good so far. I kept getting the Invalid Hours error if I tried to change the time, regardless of what I put in and it automatically changed to 23:mm? Is that just b/c the code is incomplete so far? Sorry I am still new to VBA!

    I appreciate the help!

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Return an error if text is inputted rather than a number

    Hi BladeAP,

    See the attached file which offers a couple of Options.

    Try the following (tested and working):
    Please Login or Register  to view this content.

    Alternately, you could lock the Text Box, and use a couple of Spin Buttons to control the hours and minutes.
    Please Login or Register  to view this content.
    To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module. This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. dim i as Integer). http://www.cpearson.com/excel/DeclaringVariables.aspx

    Lewis

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Return an error if text is inputted rather than a number

    I am debugging at the moment.

    Try the revised userform.

    This version incorporates that improvement I spoke of.
    Attached Files Attached Files
    Last edited by mehmetcik; 10-28-2014 at 05:02 PM.

  8. #8
    Registered User
    Join Date
    10-15-2014
    Location
    DC
    MS-Off Ver
    2010 (work) / 2013 (home)
    Posts
    15

    Re: Return an error if text is inputted rather than a number

    Quote Originally Posted by LJMetzger View Post
    Hi BladeAP,

    See the attached file which offers a couple of Options.

    Try the following (tested and working):
    Please Login or Register  to view this content.

    Alternately, you could lock the Text Box, and use a couple of Spin Buttons to control the hours and minutes.
    Please Login or Register  to view this content.
    To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module. This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. dim i as Integer). http://www.cpearson.com/excel/DeclaringVariables.aspx

    Lewis
    YES! The first option worked great! I'll look into Spin Buttons and declaring variables for future instances. Appreciate the help!

  9. #9
    Registered User
    Join Date
    10-15-2014
    Location
    DC
    MS-Off Ver
    2010 (work) / 2013 (home)
    Posts
    15

    Re: Return an error if text is inputted rather than a number

    Quote Originally Posted by mehmetcik View Post
    I am debugging at the moment.

    Try the revised userform.

    This version incorporates that improvement I spoke of.
    Thanks! This code looks pretty neat, I will try it!

+ 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. I need to get give each row inputted a unique number for later editing
    By tarmacfitter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2014, 10:19 AM
  2. Replies: 3
    Last Post: 06-21-2013, 07:40 AM
  3. [SOLVED] Changing the numbers in cells based on the number inputted
    By WaqasTariq in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-19-2012, 09:21 AM
  4. Excel search as text being inputted
    By YMS_1975 in forum Excel General
    Replies: 4
    Last Post: 03-21-2011, 04:58 PM
  5. Using VBA how do I return the column number of first column in a user inputted range?
    By NukedWhale in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-19-2009, 06:25 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