+ Reply to Thread
Results 1 to 4 of 4

Restrict Userform Textbox to Numbers Only

  1. #1
    Registered User
    Join Date
    04-29-2015
    Location
    UK
    MS-Off Ver
    2010
    Posts
    33

    Restrict Userform Textbox to Numbers Only

    As the title says I've been trying to make it so that a textbox on a userform can only have numbers entered into it with an error message popping up if letters are added.

    The code I've used before doesn't seem to be working and I can't figure out why:

    Please Login or Register  to view this content.
    Any ideas on a fix or what is going wrong?
    Attached Files Attached Files

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

    Re: Restrict Userform Textbox to Numbers Only

    Hi Mousiefuzz,

    My speculation is that you added a frame around the TextBox, and now the Frame is the Active Control.

    The following code seemed to work for me with your file:
    Please Login or Register  to view this content.
    Lewis

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Restrict Userform Textbox to Numbers Only

    Hi, Mousiefuzz,

    have a look at the KeyPress-Event behind the textbox to limit what may be entered:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    04-29-2015
    Location
    UK
    MS-Off Ver
    2010
    Posts
    33

    Re: Restrict Userform Textbox to Numbers Only

    Sorry for the slow reply and thank you very much for your quick answers! Unfortunately I'd left my work PC for the day when they came in but tried them out first thing this morning and both solutions work great! I honestly never knew that frames affected the code so much, guess I need to look a little more in to what they do.

    But thank you both so much for your answers, as I said, both of them worked and solved my problem perfectly.

+ 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] UserForm TextBox Validation for Whole Numbers
    By ptmuldoon in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-14-2022, 08:08 PM
  2. UserForm : textbox not filtring the numbers data
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-16-2014, 05:55 AM
  3. Restrict textbox entries to numbers
    By domnisignis18 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-11-2013, 03:48 AM
  4. restrict textbox on userform to mm/yyyy
    By lcoreilly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-22-2010, 11:40 AM
  5. [SOLVED] Max numbers of characters in userform textbox and cell
    By N E Body in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-27-2005, 02:05 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