Results 1 to 3 of 3

Thread: Number validation in Text Boxes VBA

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Three things...

    1. In order to permit floating point values to be typed in, your code must allow the user to type in a decimal point character. If that is all the user types in, then the TextBox will not contain a number, rather, it will contain just a single non-digit character... the decimal point character. So, any code that makes use of the value in the TextBox will have to test for it containing just a single decimal point character before attempting to use it as if it were a numeric value.

    2. Your code, as written, will not prevent the user from copy/pasting non-digits, non-decimal points into the TextBox, so one cannot count on the contents of the TextBox being a guaranteed numeric value (once a single decimal point character has been ruled out).

    3. I assume you missed this posting of my in response to another message in this forum... http://www.excelfox.com/forum/f2/sub...-306/#post1039. The second code box contains routine that restricts the entry to a TextBox to a floating point number and overcomes the problem outlined in #2 above; however, it suffers from the same problem as your code does as outlined in #1 above. As written, the indicated code does not pop up the MessageBox the way your code does, but that is easily fixed by replacing the Beep command with your MessageBox line.
    Last edited by Rick Rothstein; 05-17-2012 at 01:52 PM.

Similar Threads

  1. Wrap Text On Spaces Up To A Maximum Number Of Characters Per Line
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 15
    Last Post: 12-20-2016, 09:47 AM
  2. Extract Number From Alphanumeric Text
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 10
    Last Post: 09-11-2013, 10:14 PM
  3. Data Validation For Selecting Date And Week Number
    By paul_pearson in forum Excel Help
    Replies: 8
    Last Post: 06-16-2013, 05:07 AM
  4. VBA Validation List set
    By xander1981 in forum Excel Help
    Replies: 3
    Last Post: 02-15-2013, 04:07 PM
  5. Replies: 2
    Last Post: 09-25-2012, 01:30 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •