+ Reply to Thread
Results 1 to 26 of 26

Format for Canadian Postal Codes

  1. #1
    Registered User
    Join Date
    07-22-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    25

    Format for Canadian Postal Codes

    Hello,
    I need help with formatting cells for Canadian Postal Codes.

    Example: if m9b2t3 is placed in the cell Excel will update the cell to M9B 2T3

    Thank you kindly for any help.

    rmcc

  2. #2
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    this one cannot be achieved with any custom formatting, meaning, you would need to use a helper column for splitting the string into two pieces. another approach would be a VBA macro, which would do the splitting in the background and in which case you would not need a helper column.

    method with helper column, put the formula in B1:

    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    - i.s.z -
    CSE, aka Array aka { }, formulae are confirmed with CONTROL+SHIFT+ENTER.
    Replace commas ( , ) with semicolons ( ; ) in formulae, if your locale setting demands.
    All good ideas are courtesy resources from this forum as well as others around the web.
    - e.o.m -

  3. #3
    Registered User
    Join Date
    07-22-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Format for Canadian Postal Codes

    I am sorry but I don't understand where to put the codes

  4. #4
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    why don't you share an excel spreadsheet with sample data and i will set it up for you?

    here is the VBA macro method, in case you are inclined towards an automated solution:

    Please Login or Register  to view this content.
    Last edited by icestationzbra; 07-23-2012 at 03:07 PM. Reason: attached sample file

  5. #5
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    i had forgotten to attach a sample file - here it is now.

    in column A, type any postal code in any_case and hit enter > see it automatically change to UPPER_CASE with a space inserted between 3rd and 4th characters.
    Attached Files Attached Files
    Last edited by icestationzbra; 07-23-2012 at 03:06 PM. Reason: added sample file to the correct post

  6. #6
    Registered User
    Join Date
    07-22-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Format for Canadian Postal Codes

    Hi icestationzbra,
    Yes, I will share the sample data.

    Thank You very much.
    Last edited by Cutter; 07-23-2012 at 04:06 PM. Reason: Removed whole post quote

  7. #7
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    @rmcc, see my post #5 - i have uploaded a sample file in it with the code embedded. enable macros, follow the directions in that post and test with your sample data directly in that file.

  8. #8
    Registered User
    Join Date
    07-22-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Format for Canadian Postal Codes

    Hi,
    Here is the Excel sample data. rmcc-sample-data.xlsx

    Thank you kindly.

  9. #9
    Registered User
    Join Date
    07-22-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Format for Canadian Postal Codes

    Hi icestationzbra,
    I sent the excel sample file but forgot to add that excel should convert the data when it is enter. I don't want to, at a later date, select he cells then run the macro to update the text. Thank you.

  10. #10
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    here you go...

    enable macros and play with it.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    07-22-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Format for Canadian Postal Codes

    Hi icestationzbra,
    I follow your instructions and ran the macro but when i add text to the empty cell it is still not formatting the cells.
    Example, if i add m4w3t2 to the sell it stays the same as i entered it. I was hoping the after running the macro, Excel would convert the added data from m4w3t2 to M4W 3T2.

    What went wrong?

    Thanks

    rmcc

  12. #12
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    i tested the file that i had uploaded, and it works like a charm.

    when you open the file, do you see an option that i have highlighted in the attached picture below?

    rmcc_847043_23jul12_03.png

    once you click on the Options button, it should pop-up another window like the one below:

    rmcc_847043_23jul12_04.png

    on this one, you have to select Enable Content and click on OK for the macro to work (so, you do not actually RUN the macro; it gets enabled and activated and runs in the background).

    have you done all these?

  13. #13
    Registered User
    Join Date
    07-22-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Format for Canadian Postal Codes

    I am using Excel 2007. When I open the file there was nothing as what is in your images.

  14. #14
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    i am using Excel 2007 too. what Operating System are you on?

    ---------- Post added at 07:50 PM ---------- Previous post was at 07:46 PM ----------

    by the way, i have hit a bug on that file that i had uploaded earlier. i am going to open a thread in the VBA section on this issue.

    the code works fine for all columns except for the column in which you have the Data Validation and it flips out completely. so, just wait for a bit.

  15. #15
    Registered User
    Join Date
    07-22-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Format for Canadian Postal Codes

    Hi,
    I am using Windows 7 Home Premium.

    I saved the file as a new excel file with macros disabled.

    I will wait for you.

    Thank you.

  16. #16
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    rmcc, you should save it as a Macro Enabled file for Macros to work...

    only when you do that will you get the prompt for enabling macros.

    the solution is macro-based, you will need to save the file as a macro-enabled file and enable macros for the solution to work for you.

    i have created another thread for the issue with Data Validation:

    http://www.excelforum.com/excel-prog...ing-macro.html
    Last edited by icestationzbra; 07-23-2012 at 10:25 PM. Reason: link

  17. #17
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    rmcc,

    see the attached file - the macro in it was provided by Jerry Beaucaire on another thread.

    download this file as a MACRO ENABLED file. enable macros and then test it out. only text entered in columns A, B, C, D, E and G will be converted to Proper_case by this macro. column H should be handled through Custom Format, which you already have setup.
    Attached Files Attached Files

  18. #18
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    rmcc, you mentioned that you downloaded the file, but it is not working.

    take me step by step through what you did to download the file - and, first of all, did you download the file from here in this thread?

  19. #19
    Registered User
    Join Date
    07-22-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Format for Canadian Postal Codes

    OK, I am starting fresh.
    Downloading the file from this thread
    Opened the file from this thread and there is a Security Warning: Macros have been disabled
    Saved the file as an Excel-Macro Enabled Worksheet
    The Security Warning is still there
    Clicked on Options then checked Enable this content
    Typed some text in the formatted cells and it worked beautiful Thank You.

    I wasn't getting this result before.

    Now I go to my file and click on the Developers tab and choose Visual Basic
    Visual Basic opens and I see the codes in the file I downloaded from today's thread

    Now I am lost...
    How do I take those codes and add it to my file?

    Thank you kindly for your help.

    rmcc

  20. #20
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    cool - first, and major, step conquered...

    if you feel comfortable in sharing your work file with me (devoid of data, of course), i can setup the macro in it for you.

    if you want to try it yourself, here is how to do it.

    open your work file. determine which is the sheet that has the table for names, address etc. let us say it is Sheet1. now, right-click on the sheet tab where it says Sheet1. one of the options should be View Code, select that. once you select that option, a new window, know as the VB Editor in general parlance, should pop up. that window should look like the following image:

    rmcc_847043_24jul12_06.png

    the left-side pane should have Sheet1 highlighted and selected (that is the sheet tab you right-clicked on). make very sure there is nothing on the right-side pane. if there is something in there, that is probably code you need, too. so revert here in that case.

    now, switch over to this forum thread.

    take the following code (highlight all the way from Option Explicit to End Sub and copy):

    Please Login or Register  to view this content.
    after you have copied the code above, paste it within the right-side pane, just below where it says General and Declarations. now, your window should look something like this image below:

    rmcc_847043_24jul12_07.png

    that's it - click on SAVE, close the window, switch back to your spreadsheet and start plonking data in.

    remember, you have to enable macros EVERY TIME you open the file.

  21. #21
    Registered User
    Join Date
    07-22-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Format for Canadian Postal Codes

    I really want to learn how to make the macro work, but still having problems; probably gave you the wrong columns.

    Attach is the work file, but I still want to learn how; where do I put in the code which columns Excel should format?

    Thanks a lot for your help.
    Last edited by Paul; 07-24-2012 at 01:24 PM. Reason: Removed attachment as it may contain private data.

  22. #22
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Format for Canadian Postal Codes

    psst see the button top left of code click that then copy
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  23. #23
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    rmcc,

    here you go - as soon as you download this file, let me know and i will delete it from my post. you should also delete your file from your post #21.

    EDIT: file deleted.
    Last edited by icestationzbra; 07-24-2012 at 01:20 PM. Reason: file deleted

  24. #24
    Registered User
    Join Date
    07-22-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Format for Canadian Postal Codes

    icestationzbra,
    file is downloaded

    ---------- Post added at 01:55 PM ---------- Previous post was at 01:16 PM ----------

    icestationzbra
    Thank you again for your time, help and persistent.
    This file is working great. Also thanks for the advice on deleting the file -I saw where I made the mistake
    Have yourself a wonderful day.

    Sincerely,
    rmcc

  25. #25
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    rmcc,

    moderator's have removed it, so no worries, hopefully.

    if your requirement is satisfied, please close the thread as SOLVED.

  26. #26
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Format for Canadian Postal Codes

    rmcc,

    moderator's have removed it, so no worries, hopefully.

+ 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