+ Reply to Thread
Results 1 to 3 of 3

Form Textbox that only Accepts Text (no numbers)

Hybrid View

  1. #1
    Registered User
    Join Date
    06-22-2018
    Location
    South Australia
    MS-Off Ver
    Office Professional Plus 2010
    Posts
    15

    Form Textbox that only Accepts Text (no numbers)

    Hi,

    I have a form with a number of text boxes. One of which I want to only accept numbers and another I want to only accept text characters (no numbers so only the alphabet). I've been able to restrict one to numbers but I can't get the text only one to work. The coding I use for the numbers-only textbox is below (taken from another thread for TextBoxQuant) and all the attempts I've done for my other textbox (TextBoxUnit) are rubbish.

    Any help appreciated.

    Private Sub TextBoxQuant_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
        Select Case KeyAscii
          Case vbKey0 To vbKey9, vbKeyBack, vbKeyClear, vbKeyLeft, _
          vbKeyRight, vbKeyUp, vbKeyDown, vbKeyTab
          Case Else
            KeyAscii = 0
            Beep
        End Select
    End Sub
    Thanks

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Form Textbox that only Accepts Text (no numbers)

        Select Case KeyAscii
          Case Asc("a") To Asc("z"), Asc("A") To Asc("Z")
          Case vbKeyBack, vbKeyClear, vbKeyLeft, _
                vbKeyRight, vbKeyUp, vbKeyDown, vbKeyTab
          Case Else
            KeyAscii = 0
            Beep
        End Select
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    06-22-2018
    Location
    South Australia
    MS-Off Ver
    Office Professional Plus 2010
    Posts
    15

    Re: Form Textbox that only Accepts Text (no numbers)

    Perfect!

    I tried variations on that but my syntax obviously left much to be desired.

    Thanks for the speedy help.

+ 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. Numeric Textbox that accepts negative sign (-)
    By Axmed.cm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-02-2015, 05:44 AM
  2. i want to validate a cell which only accepts text not numbers
    By foramkubavat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2015, 08:53 AM
  3. TextBox that only accepts integers
    By Chaba in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-24-2014, 12:43 PM
  4. [SOLVED] Code For Date Accepts Text
    By Paige in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2006, 06:55 PM
  5. [SOLVED] Textbox accepts alpha only
    By LeLi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2005, 04:05 AM
  6. take text from form textbox and put in cell...
    By thomas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-25-2005, 09:05 PM
  7. [SOLVED] TextBox that only accepts integers?
    By Claud Balls in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2005, 07:06 PM

Tags for this Thread

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