+ Reply to Thread
Results 1 to 2 of 2

How do I restrict an inputbox to 5<= string characters?

  1. #1
    Gabe Tiger
    Guest

    How do I restrict an inputbox to 5<= string characters?

    I am still new with VBA...

    I need help writing a macro that will restrict an input to 1 to 5
    characters of the alphabet. This input should be prompted using the
    application.inputbox function.


  2. #2
    Forum Contributor
    Join Date
    08-07-2004
    Location
    Ohio, USA
    Posts
    114
    If you are referring to an inputbox on a userform, you set the "MaxLength" property to 5 in the VBE, or if you want to do it programatically, you would use textbox1.maxlength = 5.

    If you want, you can also have the focus move to the next control (tabindex) when the max length is reached by setting the "AutoTab" property to true

    To restrict only alphabetic inputs use

    Private Sub textbox1_keypress(ByVal keyascii As MSForms.ReturnInteger)
    Select Case keyascii
    Case Asc("a") To Asc("z")
    case asc("A") to asc("Z")
    Case Else: keyascii = 0
    End Select
    End Sub

    This will allow only upper and lower case letters to be entered in the inputbox.

+ 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