+ Reply to Thread
Results 1 to 4 of 4

UserForm - adding exception to text box restrictions (numbers only)

  1. #1
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Sefton
    MS-Off Ver
    MS Office 365 ProPlus
    Posts
    131

    UserForm - adding exception to text box restrictions (numbers only)

    I've found the below code which will prevent anything other than numbers being entered into the text boxes within my userform. However this means that a negative (-) symbol cannot be used. Is there any way I can keep the restriction but allow the negative symbol to also be used?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: UserForm - adding exception to text box restrictions (numbers only)

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: UserForm - adding exception to text box restrictions (numbers only)

    The code that you attached allows to use negative numbers because, for instance, 3 or -3 are both numerics and the code allows a numeric value.

    If you need you could also prevent to digit alphabet characters using the Keycode event of your control... for example, if your control is TextBox1 you can use this code:
    Please Login or Register  to view this content.
    This are codes that I used:
    8 backspace, 35 End, 36 Home, 37 left arrow, 39 right arrow, 46 Canc, 109 '-', 96 to 105 is char from 0 to 9.
    Regards,
    Antonio
    Last edited by antoka05; 10-20-2015 at 10:13 AM.

  4. #4
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Sefton
    MS-Off Ver
    MS Office 365 ProPlus
    Posts
    131

    Re: UserForm - adding exception to text box restrictions (numbers only)

    Thanks Norie that code worked.

    antoka05 - the code I posted doesn't let me enter negative numbers. The second I type '-' I get the message box pop up telling me I can only enter numbers.

+ 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] Cell Restrictions allow only numbers, no special characters
    By karimel_romeo in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 05-07-2015, 01:56 AM
  2. Excel 2007 : generating random numbers with exception
    By scbalaji in forum Excel General
    Replies: 2
    Last Post: 05-16-2012, 02:28 PM
  3. [SOLVED] Adding an exception statement
    By Biased Historian in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-02-2012, 01:40 PM
  4. [SOLVED] UserForm Error - Exception Occurred
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-02-2011, 11:26 AM
  5. Combobox on Userform Restrictions
    By CobraLAD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2007, 06:43 AM
  6. Userform: text restrictions
    By Gert-Jan in forum Excel General
    Replies: 2
    Last Post: 03-28-2006, 05:20 PM
  7. Userform; text restrictions
    By jgmiddel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2006, 02: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