+ Reply to Thread
Results 1 to 24 of 24

How to check postal code format for user form text box

  1. #1
    Registered User
    Join Date
    02-27-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    How to check postal code format for user form text box

    I'm hoping someone can help! I'm trying to create a data entry form using a userform. I've created a text box for Postal Code. In Canada, the format is A1A 1A1. I would like to validate that the person is entering the postal code in the right format when they are using the user form. I've stumbled on how to do it within the worksheet source code (http://www.excelforum.com/excel-prog...-on-entry.html), but there must be a way to do it when I initialize the user form? I'm using Excel 2010.
    Any help??

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

    Re: How to check postal code format for user form text box

    Use it as a function to evaluate valid or invalid.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-27-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: How to check postal code format for user form text box

    Sorry, you've lost me.... I'm new to this...

    My txt box is call txt_pc, how do I incorporate this with what you've given me!

    Thanks a bunch for replying!

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

    Re: How to check postal code format for user form text box

    Something like this
    To A UserForm module
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-27-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: How to check postal code format for user form text box

    Thanks Jindon!

    I was trying to load this checking before copying the data over when initializing using at button.

    So far, this is a sample of what I have:
    Please Login or Register  to view this content.
    Can I insert your code above to where I have 'Validate Postal Code?
    Or, can you tell me more about how to use it as a userform module?

    Thanks again!
    Last edited by vlady; 03-11-2013 at 01:50 AM.

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

    Re: How to check postal code format for user form text box

    1) You need to edit your last post and wrap the vba code with the code tag.
    It's a MUST rule here.
    i.e
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code]

    2) Not tested.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-27-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: How to check postal code format for user form text box

    Thanks Jindon.

    I tried the code above, but it seems to not recognized the function IsValidPostCode. It allows me to enter the Postal Code, but it doesn't matter what I enter, it keeps coming up Invalid Entry. I'm sure it's simple, it seems so close!!!!

    Any suggestions?

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

    Re: How to check postal code format for user form text box

    Quote Originally Posted by jindon View Post
    1) You need to edit your last post and wrap the vba code with the code tag.
    It's a MUST rule here.
    i.e
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code]
    Post your workbook.

  9. #9
    Registered User
    Join Date
    02-27-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: How to check postal code format for user form text box

    Book1.xlsm

    Thanks!

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

    Re: How to check postal code format for user form text box

    ...................
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    02-27-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: How to check postal code format for user form text box

    Hi Jindon,

    The xlsm file that you attached does not seem to work either. When I enter the postal code with the UserForm button in any format, it all comes back with invalid entry. The correct format should be A1A 1A1, but even when I enter that, it comes up as unvalid? Maybe I am doing something wrong?

    Thanks again!

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

    Re: How to check postal code format for user form text box

    A1a 1a1.......
    Attached Files Attached Files
    Last edited by jindon; 03-11-2013 at 02:01 AM. Reason: Password removed

  13. #13
    Registered User
    Join Date
    02-27-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: How to check postal code format for user form text box

    That's great Jindon! Can I see the code so that I can learn what you did?

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

    Re: How to check postal code format for user form text box

    Nope.

    You must edit your post #5 first.

  15. #15
    Registered User
    Join Date
    02-27-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: How to check postal code format for user form text box

    Sorry for my ignorance, I don't know what that means. As I said, I'm new to this, so if you could explain, that would be great!

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

    Re: How to check postal code format for user form text box

    1) Click on [Edit Post].

    2) Select vba code in that post and click on "#" in the menu. It will add code tag automatically.

  17. #17
    Registered User
    Join Date
    02-27-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: How to check postal code format for user form text box

    Please Login or Register  to view this content.

  18. #18
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,361

    Re: How to check postal code format for user form text box

    @ cpost, when posting codes. select the code then hit the "#" symbol to wrap it with code tags, I've done it for you but be sure to do it yourself next time.
    I think people forget the word "THANK YOU!!!!" Do you still know it???

    There is a little star ( ADD REPUTATION ) below those person who helped you. Click it to say your "PRIVATE APPRECIATION TO THEIR EFFORT ON THEIR CONTRIBUTIONS "

    Regards,
    Vladimir

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

    Re: How to check postal code format for user form text box

    Password removed.

  20. #20
    Registered User
    Join Date
    02-27-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: How to check postal code format for user form text box

    Thanks again Jindon! One more thing, any idea how I can enforce uppercase letters?

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

    Re: How to check postal code format for user form text box

    Add this to a Form module
    Please Login or Register  to view this content.

  22. #22
    Registered User
    Join Date
    02-27-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: How to check postal code format for user form text box

    Hi Jindon,

    One last thing, if I want to enforce the space between, would I change the function to this:
    Please Login or Register  to view this content.
    When I try this, it doesn't work?

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

    Re: How to check postal code format for user form text box

    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    02-27-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: How to check postal code format for user form text box

    Thank you so much Jindon for all your help and patience! I've learned so much! Hope others will see this as valuable as I did!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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