+ Reply to Thread
Results 1 to 13 of 13

Match based on part of a postcode (UK)

  1. #1
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Match based on part of a postcode (UK)

    I have a list of beginning parts of UK post codes that (ie N1, EC1 etc) that I need to match up with full post codes (N78TZ, EC14BY etc) but i need the macro to identify just the beginning parts , which are sometimes 2 or 3 digits long....how can this be achieved?

    sample sheet included. See colomn A has the full post code, it needs to match that to the list in the other sheet (called PC) and in Col B return either A or B (or Other if the post code doesnt feature)
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Match based on part of a postcode (UK)

    This is easy in theory.

    Use the find function to find all occurrences of your text.

    then reject all those where the text isn't the leftmost part of the selected cell.

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Match based on part of a postcode (UK)

    Try the attached.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Match based on part of a postcode (UK)

    AB33 - that is fantastic but it dosnt quite work.....try putting in the postcode SE64BY for example, and it should bring back the result of B (SE6 = B) but it brings back "Other" instead.
    Strangely, if you then add WC2E9EN to the list and rerun the macro, it changes SE64BY to an A, and WC2E9EN is returned as an Other instead of an A

  5. #5
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Match based on part of a postcode (UK)

    Hi,

    Can I ask if this is in anyway related to this post? Seems like a remarkable coincidence if not, especially since the OP is asking for "So that when I paste the postcodes into another sheet along with other info excel can tell by the first 2 letters in the postcode..."

    http://www.excelforum.com/excel-form...ategories.html

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Match based on part of a postcode (UK)

    Try the attached.
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Match based on part of a postcode (UK)

    ab33,

    thank you for the quick response.....
    but i found an error - if you put in the postcode sw197by it thinks it is a Code A (i assume because it thinks it is SW1 instead of SW19)?

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Match based on part of a postcode (UK)

    Yes, the code works on the first match, but not the closest match.

    For e.g., SE64BY, closest match is found in row 77, but the code returns row 22.

  9. #9
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Match based on part of a postcode (UK)

    Quote Originally Posted by AB33 View Post
    Yes, the code works on the first match, but not the closest match.

    For e.g., SE64BY, closest match is found in row 77, but the code returns row 22.
    So it isn't possible to get the closest match?

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Match based on part of a postcode (UK)

    The honest answer is: I do not know. It may be possible with regular expression or a formula, but as far as VBA is concerned, even if you were to use the find and match partial function, it will return the same as instr function.

  11. #11
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Match based on part of a postcode (UK)

    try the following file
    Attached Files Attached Files

  12. #12
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Match based on part of a postcode (UK)

    mehmetcik
    thank you for your code - I was wondering how it works as it doesnt seem to be able to identify N19TZ (which is N1, but it classes it as a N19)

    I wonder if there is some logic that can be given in the macro to help identify it. From first glance to get round my problem above, you could try to get the macro to read the length of the postcode, if its 5 alphanumeric digits then it could only be N1, of its more than 5 it has to be N19

    Postcode formats can only take the following formats (where A=alphabetic and N = number)

    AN NAA (N1 9TZ)
    ANN NAA (N17 1NW)
    AAN NAA (CR2 6XH)
    AANN NAA (DN55 1PT)
    ANA NAA (W1A 1HQ)
    AANA NAA (EC1A 6BB)
    Last edited by nickmax1; 10-18-2013 at 06:43 AM.

  13. #13
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Match based on part of a postcode (UK)

    Hi

    I don't see that.

    The example I sent you works as per your request,

+ 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] Postcode Match: Cross Reference from another list
    By denise001 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-25-2013, 06:22 AM
  2. [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
  3. Match 2 lists based on Part Number
    By jamezgreen in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-08-2012, 01:59 PM
  4. Route Run Distances based on postcode area
    By marklister in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-07-2012, 11:33 AM
  5. Match postcode then show matching data
    By Cornfused in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-31-2011, 02:09 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