Results 1 to 4 of 4

Formatting Excel Userform textbox input into one of two specific formats

Threaded View

serose14 Formatting Excel Userform... 08-14-2014, 12:36 PM
HaHoBe Re: Formatting Excel Userform... 08-14-2014, 01:19 PM
HaHoBe Re: Formatting Excel Userform... 08-14-2014, 01:38 PM
serose14 Re: Formatting Excel Userform... 08-14-2014, 01:58 PM
  1. #1
    Registered User
    Join Date
    07-31-2014
    Location
    Ephrata, PA
    MS-Off Ver
    2007
    Posts
    7

    Formatting Excel Userform textbox input into one of two specific formats

    I am new to VBA. I am constructing a VBA userform. I want to restrict input into one of the textboxes to either a 16 or 21 character string with only numerals or spaces (the spaces are to be entered automatically). The first 5 digits are static for both formats, i.e.

    format for 16 digit is "84271 ##### ####"

    format for 21 digit is "84271 ##### #### ####"

    I have created the following code:

    Private Sub expresscode_Exit(ByVal Cancel As MSForms.ReturnBoolean)
      Let expresscode.Text = Format$(expresscode.Text, "84271 ##### #### ####")
       If Len(expresscode.Value) = 21 Then
        Exit Sub
      Let expresscode.Text = Format$(expresscode.Text, "84271 ##### ####")
       ElseIf Len(expresscode.Value) = 16 Then
        Exit Sub
      Else
        MsgBox "Please enter a 9 or 13 digit number"
          Cancel = True
       End If
    End Sub

    This tests and works correctly for the 21 character input. It is not reading the 16 character format as when I enter 9 numerals, I get the following:

    84271 1 2345 6789

    and my message box appears asking for a 9 or 13 digit input.

    Any help would be appreciated.

    Thank you.
    Last edited by serose14; 08-14-2014 at 01:36 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Pass Value of combobox selected in Userform as input to textbox of other userform
    By Pradeepg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2013, 10:32 AM
  2. input the value of a Combobox and a textbox to a TEXTBOX directly from a userform
    By Gordonhk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-11-2013, 03:25 PM
  3. [SOLVED] UserForm TextBox formats - Display as Decimal, Read as Percent. Possible?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-12-2013, 11:40 PM
  4. Use textbox input and VLookup to update another textbox on same userform
    By gcoug in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-22-2011, 10:39 AM
  5. Userform textbox number formats
    By PhilM in forum Excel General
    Replies: 2
    Last Post: 06-07-2006, 06:15 AM

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