+ Reply to Thread
Results 1 to 7 of 7

Textbox to accept integers or decimal numbers only

  1. #1
    Forum Contributor Bob@Sun's Avatar
    Join Date
    09-03-2009
    Location
    Montuak, Usa
    MS-Off Ver
    Excel 2007
    Posts
    438

    Textbox to accept integers or decimal numbers only

    Hello,

    I am using the flowing code to validate the entry in the textbox. The problem is that It allows me to enter numbers like 1.1... which is not a valid decimal number

    Please Login or Register  to view this content.
    I tried with many different codes but they all allow to enter multiple dots/commas.
    Could you help me to modify this code to allow valid integer or decimal numbers only?

    Thanks a lot!
    BK

  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: Textbox to accept integers or decimal numbers only

    BK,

    Try using the following. It detects if each character as it is entered, and only allows numbers and one decimal:

    Please Login or Register  to view this content.
    Hope this helps

  3. #3
    Forum Contributor Bob@Sun's Avatar
    Join Date
    09-03-2009
    Location
    Montuak, Usa
    MS-Off Ver
    Excel 2007
    Posts
    438

    Re: Textbox to accept integers or decimal numbers only

    Thanks a lot! that worked perfectly!!!

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Textbox to accept integers or decimal numbers only

    or

    Please Login or Register  to view this content.



  5. #5
    Registered User
    Join Date
    07-22-2013
    Location
    Dayton, OH
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Textbox to accept integers or decimal numbers only

    I used the code posted by Tigeravatar. Works perfect! Thanks.

  6. #6
    Registered User
    Join Date
    11-22-2017
    Location
    Seattle, Washington
    MS-Off Ver
    2010
    Posts
    1

    Re: Textbox to accept integers or decimal numbers only

    Tigeravatar's solution only works if you are typing on the right side of the text. Here is my code that works in all cases. I chose to handle it on the key down event.

    Please Login or Register  to view this content.

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,917

    Re: Textbox to accept integers or decimal numbers only

    bigboii thanks for teh input

    Not that it's a big deal, but did you notice that this thread is over 4 years old now?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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