+ Reply to Thread
Results 1 to 4 of 4

Restricting textbox entry to a less than a given number

  1. #1
    Registered User
    Join Date
    08-20-2012
    Location
    Bigtown,IL
    MS-Off Ver
    Excel 2003
    Posts
    5

    Restricting textbox entry to a less than a given number

    I have run in to a problem with a textbox. I am entering data as a number less than 6. I have the textbox set so only numbers can be entered using the following code:

    Please Login or Register  to view this content.
    I thought I had the problem licked with the following code:

    Please Login or Register  to view this content.
    The problem is when I enter the number 7, 8, or 9 my message pops up. If I enter a 10 the textbox allows the entry. What I do not know is how to get the string entered in the textbox to be seen as a number "10" not "1" and "0" which are allowed numbers. Does anyone have any suggestions?
    Last edited by Cutter; 08-30-2012 at 08:20 PM. Reason: Added code tags

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Restricting textbox entry to a less than a given number

    WML0068,

    In the future, please wrap your code in code tags. See forum rules (link in my sig) for how.
    As for your question, attached is a sample workbook based on the criteria you described.
    The workbook has one sheet that contains a button. The button is only used to launch the test userform, and it is assigned to this macro:
    Please Login or Register  to view this content.


    The userform only has a textbox. However, the textbox is coded to only allow any valid number less than 6. This is the complete userform code with comments:
    Please Login or Register  to view this content.


    Hopefully you can adapt this to fit your needs.

    [EDIT]
    Just realized that you don't need to use "Public frmEnableEvents". "Dim frmEnableEvents" should be just fine (and is actually recommended, I just didn't think about it when creating the sample).
    Attached Files Attached Files
    Last edited by tigeravatar; 08-30-2012 at 04:10 PM. Reason: Added edit regarding Public vs Dim
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    08-20-2012
    Location
    Bigtown,IL
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Restricting textbox entry to a less than a given number

    Tigeravatar,

    Sorry for not getting things in the right format I am new to communicating in a form. Also sorry about not getting back to you sooner work calls. I did want to thank you for all your help. It took me a bit to get all the other variable and conditions to work together but once I got on to it your code works brilliantly.

    Thank Again,
    WML0068

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Restricting textbox entry to a less than a given number

    @ WML0068

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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