+ Reply to Thread
Results 1 to 10 of 10

UK Postcode Split

  1. #1
    Registered User
    Join Date
    08-05-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    27

    UK Postcode Split

    Hi,

    I currrently have a VBA script for separating UK postcodes based on The postcodes first section and placing them in a new sheet. What I am now trying to do is change this slightly to allow me to split a large sheet based on just the letters before the first number in the postcode.

    Below is the format for UK postcodes if you are unfamiliar with it.

    A9 9AA
    A99 9AA
    AA9 9AA
    AA99 9AA

    This is the script I have currently...

    Please Login or Register  to view this content.
    I have made bold the line which I think I need to change. I believe it is currently splitting the postcode by detecting the space in the cell. Could be wrong though.

    Basically right now it sorts postcode like this: AB1 AB2 AB3 CA1 CA2 CA3
    I want it to sort like: AB CA


    If anyone can help me with this that would be great!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,155

    Re: UK Postcode Split

    Try:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: UK Postcode Split

    Another option is to use Regex

    Please Login or Register  to view this content.
    If there is match, the RegExp function will return at least 1 and max 2 non-digits from the beginning of the cell content or else will return vbNullString
    If you are pleased with a member's answer then use the Star icon to rate it.

  4. #4
    Registered User
    Join Date
    08-05-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    27

    Re: UK Postcode Split

    Both Solutions work perfectly.

    Thank you both for your help!

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,155

    Re: UK Postcode Split

    You're welcome. Thanks for the rep.

  6. #6
    Registered User
    Join Date
    08-05-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    27

    Re: UK Postcode Split

    Sorry one last request.

    Would it be possible to add the total number of rows onto the each postcode sheet name?

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,155

    Re: UK Postcode Split

    I would suggest that you just loop through the worksheets, count the rows on each one, and then concatenate that with the original sheet name, perhaps separated by a space so that it will be easy to locate and update if required.

  8. #8
    Registered User
    Join Date
    08-05-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    27

    Re: UK Postcode Split

    Yeah that's fine. I had been doing that anyway, was just wondering if there was a quick solution to it.

    Don't worry about it.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,155

    Re: UK Postcode Split

    Well, you can't do it until the processing is complete otherwise you wouldn't be able to locate the sheet for the post code group. So looping when the process is complete is the only way AFAICS

  10. #10
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: UK Postcode Split

    Quote Originally Posted by TMS View Post
    Well, you can't do it until the processing is complete otherwise you wouldn't be able to locate the sheet for the post code group. So looping when the process is complete is the only way AFAICS
    Well, one possible approach is to create collection/dictionary with postcode as key (the postcode part) and respective target sheet as object/target sheet name (depending on if you are using collection or dictionary). Then every time you can get the target ws from the collection and you can change the sheet name with every record added to that sheet. not that it will be very useful. better loop at the end :-)

+ 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. Replies: 4
    Last Post: 05-29-2014, 12:05 AM
  2. Postcode to postcode distance checker
    By KerryLL1221 in forum Excel General
    Replies: 1
    Last Post: 02-21-2014, 09:42 AM
  3. Lookup postcode zone from postcode
    By Elmholt in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-08-2013, 09:26 AM
  4. [SOLVED] Split cells postcode from address
    By dsthome in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-10-2013, 02:15 AM
  5. Split GB Postcode ranges in to rows!!!!
    By 2013boris in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-11-2013, 12:31 PM
  6. [SOLVED] Split postcode ranges into rows
    By 2013boris in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-10-2013, 09:41 AM
  7. [SOLVED] Help needed trimming full postcode address to postcode sector.
    By Mikey7346 in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 08-10-2012, 05:11 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