+ Reply to Thread
Results 1 to 8 of 8

Formula Needed To Truncate Postcodes

  1. #1
    Registered User
    Join Date
    12-23-2012
    Location
    London, England
    MS-Off Ver
    Mac 2011
    Posts
    8

    Formula Needed To Truncate Postcodes

    Hi,

    I'm collecting postcodes from a website then importing them into Excel for analysis.

    For reasons beyond my control, 5, 6 and 7 digit postcodes are being submitted in one of the following formats;

    N1 1AA
    N11AA
    N11 1AA
    N111AA
    NN1 1AA
    NN11AA
    NN11 1AA
    NN111AA

    I need a formula that can 'analyse' these different formats and create a new result that shows only the prefix.

    I guess the way it would work would be to first remove (or ignore) any spaces. This would then result in all the above variations being shown as either;

    N11AA
    N111AA
    NN11AA
    NN111AA

    It would then need to figure out whether to return a result of 3 or 4 characters. In other words, the above results would then be shortened in the following way.

    N11AA would become N1
    N111AA would become N11
    NN11AA would become NN1
    NN111AA would become NN11

    So, if you look at each possible variation, you'd get the following for each.

    N1 1 AA would become N1
    N11AA would become N1
    N11 1AA would become N1
    N111AA would become N11
    NN1 1AA would become N1
    NN11AA would become NN1
    NN11 1AA would become N1
    NN111AA would become NN11

    Can anyone tell me a formula (or formulas) that can achieve this?

    Many (many) thanks,
    Dom
    Last edited by Dom2066; 12-26-2012 at 09:33 PM.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,972

    Re: Formula Needed To Truncate Postcodes

    assuming your data is in A1, down, use this, copied down...
    =LEFT(SUBSTITUTE(A1," ",""),LEN(SUBSTITUTE(A1," ",""))-3)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    12-23-2012
    Location
    Dubai, United Arab Emirates
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Formula Needed To Truncate Postcodes

    Hi Dom,

    I think you've nailed most of your answer in the post. The only bit missing I think is the exclusion of the last 3 characters from the text without spaces. Steps as folls:

    Original: NN11 1AA
    Remove spaces: NN111AA
    Length of modified text: 7
    Characters to remove (1AA): 3
    Final isolation: LEFT("NN111AAA",7-3)

    The attached workbook breaks down the formulas for each of the steps and has one one formula that combines all the steps. Hope this helps.

    best regards, dims

    Postcodes.xlsx
    Last edited by darth.dims; 12-23-2012 at 05:43 PM.

  4. #4
    Registered User
    Join Date
    12-23-2012
    Location
    London, England
    MS-Off Ver
    Mac 2011
    Posts
    8

    Re: Formula Needed To Truncate Postcodes

    Thanks for your help, guys.

    So simple once you know how.

    Happy New Year!

    Dom

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,972

    Re: Formula Needed To Truncate Postcodes

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a relatively new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon 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 those who helped.

  6. #6
    Registered User
    Join Date
    12-23-2012
    Location
    Dubai, United Arab Emirates
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Formula Needed To Truncate Postcodes

    Thanks FDibbins for the quick info. I was wondering how I could go about marking one of my other discussions [Solved]!

  7. #7
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Formula Needed To Truncate Postcodes

    Another shorter way..

    Please Login or Register  to view this content.
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  8. #8
    Registered User
    Join Date
    12-23-2012
    Location
    Dubai, United Arab Emirates
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Formula Needed To Truncate Postcodes

    Should work for every instance except for the first one: "N1 1 AA" towards end of Dom's post. Only place where "1AA" isn't grouped together.

+ 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