+ Reply to Thread
Results 1 to 10 of 10

Help With Canadian Postal Code In Userform

  1. #1
    Registered User
    Join Date
    12-02-2013
    Location
    Miami
    MS-Off Ver
    Excel 2010
    Posts
    89

    Help With Canadian Postal Code In Userform

    Hello All,

    I have a Useform with a textbox where I would like to input the Canadian Postal Code with this format XXX XXX, Please notice there is an space in the middle. How could I input caracters and the checkbox recognize it has to put an space in the middle and only able to type 6 caracters (letters and numbers)

    Thank you in advance

    Regards,
    Last edited by eddyrcabrera79; 12-04-2013 at 03:00 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Help With Canadian Postal Code In Userform

    Hello eddycabrera79,

    This example assumes the name of the TextBox is "TextBox1". This limits the user input to six characters and then inserts a space.

    UserForm Code
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Help With Canadian Postal Code In Userform

    Hello,

    See if this helps

    Please Login or Register  to view this content.
    This code is for a textbox1 modify to match your textbox name.

    Thanks

  4. #4
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Help With Canadian Postal Code In Userform

    By the way Leith just reminded me I forgot something. the initial value for the maxLength.

    Thanks Leith

    So this is my final code with everything:

    Please Login or Register  to view this content.
    Thanks

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Help With Canadian Postal Code In Userform


  6. #6
    Registered User
    Join Date
    12-02-2013
    Location
    Miami
    MS-Off Ver
    Excel 2010
    Posts
    89

    {Help With Canadian Postal Code In Userform

    Thank you Leith and Fredlo for your help.

    This code worked fine for me

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    TextBox1.Text = Left(TextBox1.Text, 3) & " " & Right(TextBox1.Text, 3)
    End Sub

    Private Sub UserForm_Initialize()
    TextBox1.MaxLength = 6
    End Sub

    I forgot one thing, the Canadian Postal code is a combination of numbers and letters in this way M1M 1M1, Is there a way to resctirc the entry to this format?
    Last edited by eddyrcabrera79; 12-04-2013 at 02:52 AM.

  7. #7
    Registered User
    Join Date
    12-02-2013
    Location
    Miami
    MS-Off Ver
    Excel 2010
    Posts
    89

    Re: Help With Canadian Postal Code In Userform

    Thank you Leith
    This code worked fine for me

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    TextBox1.Text = Left(TextBox1.Text, 3) & " " & Right(TextBox1.Text, 3)
    End Sub

    Private Sub UserForm_Initialize()
    TextBox1.MaxLength = 6
    End Sub

    I forgot one thing, the Canadian Postal code is a combination of numbers and letters in this way M1M 1M1, Is there a way to resctirc the entry to this format?

  8. #8
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Help With Canadian Postal Code In Userform

    Hello see if this helps,

    Please Login or Register  to view this content.
    Thanks

  9. #9
    Registered User
    Join Date
    12-02-2013
    Location
    Miami
    MS-Off Ver
    Excel 2010
    Posts
    89

    Re: Help With Canadian Postal Code In Userform

    thank you so much

  10. #10
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Help With Canadian Postal Code In Userform

    You are welcome

+ 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. Format Canadian Postal Code on Entry
    By Gos-C in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 03-24-2019, 04:20 PM
  2. Distance between Canadian Postal Codes
    By lesleyhollett in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-17-2013, 10:47 AM
  3. [SOLVED] Format for Canadian Postal Codes
    By rmcc in forum Excel General
    Replies: 25
    Last Post: 07-24-2012, 02:04 PM
  4. Adding spaces to Canadian postal code
    By loren.silverman in forum Excel General
    Replies: 3
    Last Post: 03-01-2012, 10:02 PM
  5. [SOLVED] Using excel 2003 cannot see Canadian Postal Codes
    By PW in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-08-2005, 03:25 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