+ Reply to Thread
Results 1 to 15 of 15

Need help on converting a list of Canadian Postal code to ranges

  1. #1
    Registered User
    Join Date
    03-26-2024
    Location
    Canada
    MS-Off Ver
    Excel
    Posts
    5

    Question Need help on converting a list of Canadian Postal code to ranges

    I am trying to figure out how to convert a list of Canadian postal codes into ranges. The list I have is over 800k lines. My goal is to combine any sequential postal codes that fall within the same city into a range, and any stand alone postal code will be entered as a "range" by itself.

    1st chart is a snippet of my raw data

    2nd chart is how I want it to look (from and to postal codes / city)

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by 6StringJazzer; 03-27-2024 at 01:57 PM. Reason: fixed data format to be readable

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Need help on converting a list of Canadian Postal code to ranges

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not told us about this. You are required to do so. Cross-posts are allowed but you must provide a link to your posts on other sites.

    Please see Forum Rule #7 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important: https://excelguru.ca/a-message-to-forum-cross-posters/

    I am providing the link because it's your first post.

    https://www.mrexcel.com/board/thread...-zone.1256285/
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Need help on converting a list of Canadian Postal code to ranges

    As an example, I don't see how this is a "range" or how it is derived from the first list.

    T0A 0A0 T0A 0A0 ABEE, AB

  4. #4
    Registered User
    Join Date
    03-26-2024
    Location
    Canada
    MS-Off Ver
    Excel
    Posts
    5

    Re: Need help on converting a list of Canadian Postal code to ranges

    It would be its own "range" (from and to) as I do not want to include anything in between T0A 0A0 and T0A 0E1

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Need help on converting a list of Canadian Postal code to ranges

    I don't see how any of them are a "range". Please pick any one of them and explain how it is derived from the first list.

  6. #6
    Registered User
    Join Date
    03-26-2024
    Location
    Canada
    MS-Off Ver
    Excel
    Posts
    5

    Re: Need help on converting a list of Canadian Postal code to ranges

    for example:

    Acheson, AB - (from) T7X 6A1 will be the lower limit and (to) T7X 6A9 will be the upper limit.
    Acheson, AB - (from) T7X 6B1 will be the lower limit and (to) T7X 6B9 will be the upper limit.
    and so on

    Whereas Acme, AB will be its own range because T0M 0A1 and T0M 0A2 does not exist on my data. So it will show as:

    T0M 0A0 (From postal code) - T0M 0A0 (To postal code) - Acme, AB

    T0M 0A3 (From postal code) - T0M 0A3 (To postal code) - Acme, AB

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Need help on converting a list of Canadian Postal code to ranges

    Now I see what's going on. Your data was not formatted so it just looked like gobbledy-gook to me because I am not familiar with Canadian postal code formats. (A quick explanation of that up front could have saved time.) When you just paste in data, all spaces and tabs are compressed out when the post is displayed.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Need help on converting a list of Canadian Postal code to ranges

    How do you define "sequential"? Why don't you consider (for Acheson) T7X 6A9 to T7X 6B1 be sequential? Is there a T7X 6B0 that is not included in that range?

    I think this is going to require VBA. Can you provide a somewhat larger sample set for testing? .xlsx file attachments are limited to 1MB, .zip files are limited to 9.77MB.

  9. #9
    Registered User
    Join Date
    03-26-2024
    Location
    Canada
    MS-Off Ver
    Excel
    Posts
    5

    Re: Need help on converting a list of Canadian Postal code to ranges

    For Acheson, I cannot consider T7X 6A9 to T7X 6B1 as a sequence as I do not have T7X 6B0 included in the data.

    I have attached a sample data
    Attached Files Attached Files

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Need help on converting a list of Canadian Postal code to ranges

    Here is a trial solution. I think your sample output has an error. Your sample output has this row

    Values as displayed
    F
    G
    H
    7
    T7X 6B1
    T7X 6B9
    ACHESON, AB
    Output



    but the data does not include T7X 6B5, so that range has to be split into two.

    Values as displayed
    A
    B
    15
    T7X 6B1
    ACHESON, AB
    16
    T7X 6B2
    ACHESON, AB
    17
    T7X 6B3
    ACHESON, AB
    18
    T7X 6B4
    ACHESON, AB
    19
    T7X 6B6
    ACHESON, AB
    20
    T7X 6B7
    ACHESON, AB
    21
    T7X 6B8
    ACHESON, AB
    22
    T7X 6B9
    ACHESON, AB
    RAW DATA
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,059

    Re: Need help on converting a list of Canadian Postal code to ranges

    With a Helper column in column C,
    C2=IFERROR(IF(AND(LEFT(A2,6)=LEFT(A1,6),OR(--RIGHT(A2,1)=--RIGHT(A1,1)+1)),C1,C1+1),1), copy down.

    From Postal Code,
    E2=XLOOKUP(SEQUENCE(MAX($C$2:$C$1224)),$C$2:$C$1224,$A$2:$A$1224,,0,1)

    To Postal Code,
    F2=XLOOKUP(SEQUENCE(MAX($C$2:$C$1224)),$C$2:$C$1224,$A$2:$A$1224,,0,-1)

    City,
    G2=XLOOKUP(SEQUENCE(MAX($C$2:$C$1224)),$C$2:$C$1224,$B$2:$B$1224,,0,1)

    Formulas for earlier Excel version in workbook.
    Attached Files Attached Files

  12. #12
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,427

    Re: Need help on converting a list of Canadian Postal code to ranges

    Here is a solution for the whole table including the headers with a single cell formula (everything in one go; No copy needed):

    Please empty all expected results and try:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    03-26-2024
    Location
    Canada
    MS-Off Ver
    Excel
    Posts
    5

    Re: Need help on converting a list of Canadian Postal code to ranges

    this works!! thank you so much!!!

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,847

    Re: Need help on converting a list of Canadian Postal code to ranges

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED. You can also access the SOLVED tag by editing the opening post and choosing SOLVED from the drop-down to the left of the title box.

    Also, if you have not already done so, remember that you can reward anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  15. #15
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,427

    Re: Need help on converting a list of Canadian Postal code to ranges

    You are Welcome!

    Thanks for the feedback and rep . Glad to have helped.

+ 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. [SOLVED] Canadian Postal Code Validation?
    By Ulchie in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 01-10-2020, 02:07 PM
  2. 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
  3. Canadian postal code format
    By SLN in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 09-15-2016, 08:25 AM
  4. Canadian Postal Code format
    By nmurphy2 in forum Office 365
    Replies: 4
    Last Post: 10-02-2014, 01:01 AM
  5. [SOLVED] Userform for canadian postal code validation?
    By calvinle in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-01-2014, 01:03 PM
  6. [SOLVED] Help With Canadian Postal Code In Userform
    By eddyrcabrera79 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-04-2013, 08:16 PM
  7. Adding spaces to Canadian postal code
    By loren.silverman in forum Excel General
    Replies: 3
    Last Post: 03-01-2012, 10:02 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