Closed Thread
Results 1 to 9 of 9

Generate every value between two values (letters and numbers)

  1. #1
    Registered User
    Join Date
    11-27-2018
    Location
    Chicago, IL
    MS-Off Ver
    Office 2019 Professional
    Posts
    14

    Generate every value between two values (letters and numbers)

    I have a list of Canadian postal code ranges (A0A1A0-A0A4Z9, A0B1A0-A0B3Z9, etc.). I need to generate every postal code within each range to create a full list

    The postal codes are sequential. A0A1A0 would be followed by A0A1A1, A0A1A2, A0A1A3, etc. After A0A1A9, the next code would be A0A1B0.

    The attached file is the exact one I'm working from. Is there a simple formula or VBA based way to do this?
    Attached Files Attached Files
    Last edited by benexclaimed; 07-08-2019 at 01:46 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate every value between two values (letters and numbers)

    You realize that's close to 250,000 postal codes? What would you do with them?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    11-27-2018
    Location
    Chicago, IL
    MS-Off Ver
    Office 2019 Professional
    Posts
    14

    Re: Generate every value between two values (letters and numbers)

    Yes, I realize it'll be a lot of postal codes.

    I have a list of about 241,000 shipments. I need to determine whether the ship from / ship to postal code on any of those shipments is contained in one of those ranges. The list of postal codes determine whether a carrier (FedEx in this case) will assign an out of area fee to the shipment.
    Last edited by benexclaimed; 07-08-2019 at 01:45 PM.

  4. #4
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Generate every value between two values (letters and numbers)

    **** Revise formula, should be correct *****

    This is a combination of Formula and Power Query.

    B2:C2
    =(CODE(MID(MID($A2,COLUMNS($B2:B2)*7-3,3),2,1))-65)*10+SUM(MID(MID($A2,COLUMNS($B2:B2)*7-3,3),{1,3},1)*{260,1})

    Data > From Table > Advance editor > Paste code below
    Please Login or Register  to view this content.
    Load table to E1

    G2
    =E2&INT(F2/260)&CHAR(MOD(INT(F2/10),26)+65)&RIGHT(F2)


    Right click at E2 and Refresh to get full 231k list
    Attached Files Attached Files
    Last edited by Bo_Ry; 07-05-2019 at 01:23 PM. Reason: Revise formula, should be correct now

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate every value between two values (letters and numbers)

    You don't need to list all the codes to do that. Split col A into two columns using Text to columns, and you can use a simple, fast formula:

    A
    B
    C
    D
    E
    F
    1
    From
    To
    Code
    Group
    2
    A0A1A0 A0A4Z9 A0A1A0 A0A1A0-A0A4Z9 E2: =IFERROR(IF(VLOOKUP(D2, $A$2:$B$329, 2) >= D2, LOOKUP(D2, A2:A329) & "-" & VLOOKUP(D2, $A$2:$B$329, 2), "---"), "---")
    3
    A0B1A0 A0B3Z9 U1G3Y0 ---
    4
    A0C1A0 A0C2Z9 G8K0R1 G8K0A0-G8K3Z9
    5
    A0E1A0 A0E3Z9 I3U6Q5 ---
    6
    A0G1A0 A0G4Z9 V0N0L1 V0N0A0-V0N2Z9
    7
    A0H1A0 A0H2Z9 P9A3G2 P9A0A0-P9A4Z9
    8
    A0J1A0 A0J1Z9
    9
    A0K1A0 A0K5Z9
    10
    A0L1A0 A0L1Z9
    11
    A0M1A0 A0M1Z9
    12
    A0N1A0 A0N2Z9
    13
    A0P1A0 A0P1Z9
    14
    A0R1A0 A0R1Z9
    15
    A1S0A0 A1S1Z9
    Last edited by shg; 07-05-2019 at 01:46 PM.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate every value between two values (letters and numbers)

    You have some invalid postal codes:

    A
    B
    1
    From
    To
    269
    T1O1A0 T1O1Z9
    325
    X1O1A0 X1O1Z9
    329
    Y1O1A0 Y1O1Z9


    I think the valid codes expand to 177,200.

  7. #7
    Registered User
    Join Date
    11-27-2018
    Location
    Chicago, IL
    MS-Off Ver
    Office 2019 Professional
    Posts
    14

    Re: Generate every value between two values (letters and numbers)

    Bo_Ry: Thank you, that's perfect.

    shg: Your solution doesn't recognize the postal codes in between, as far as I can see. It'd capture A0A1A0 and A0A4Z9, but not A0A1A1, for instance.

  8. #8
    Registered User
    Join Date
    03-04-2024
    Location
    Toronto, Canada
    MS-Off Ver
    365
    Posts
    2

    Re: Generate every value between two values (letters and numbers)

    Quote Originally Posted by Bo_Ry View Post
    **** Revise formula, should be correct *****

    This is a combination of Formula and Power Query.

    B2:C2
    =(CODE(MID(MID($A2,COLUMNS($B2:B2)*7-3,3),2,1))-65)*10+SUM(MID(MID($A2,COLUMNS($B2:B2)*7-3,3),{1,3},1)*{260,1})

    Data > From Table > Advance editor > Paste code below
    Please Login or Register  to view this content.
    Load table to E1

    G2
    =E2&INT(F2/260)&CHAR(MOD(INT(F2/10),26)+65)&RIGHT(F2)


    Right click at E2 and Refresh to get full 231k list

    This almost fully worked the only area where i am facing issues is for example
    the range is R2P2W7-R2V4E7 it goes up to R2P4E7 doesnt give me R2P4E8 to R2V4E7

  9. #9
    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,869

    Re: Generate every value between two values (letters and numbers)

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #1 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    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.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Generate a column of numbers and letters
    By Skinnymarinky in forum Excel General
    Replies: 4
    Last Post: 02-04-2017, 03:05 PM
  2. Replies: 8
    Last Post: 01-19-2017, 01:38 PM
  3. Automatic Generate Numbers based on already assigned letters
    By sunil31 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 12-01-2015, 07:48 AM
  4. Automatic Generate Numbers based on already assigned letters
    By sunil31 in forum Excel Formulas & Functions
    Replies: 23
    Last Post: 11-28-2015, 11:44 PM
  5. Generate random Alphanumeric with two letters and three numbers
    By Ochimus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-25-2015, 09:19 PM
  6. Function to Generate Random Numbers and Letters
    By jason_kelly in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-14-2010, 03:39 PM
  7. Auto generate numbers and letters as password
    By _bones_ in forum Excel General
    Replies: 1
    Last Post: 01-01-2010, 07:30 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