+ Reply to Thread
Results 1 to 8 of 8

Matching with variable identifier (kind of)

  1. #1
    Registered User
    Join Date
    03-12-2020
    Location
    UK
    MS-Off Ver
    365
    Posts
    12

    Matching with variable identifier (kind of)

    Hi all,

    I'm struggling to work out a formula, and wondering if you guys can help...

    I'm wanting to match a postcode with the first part of a postcode so I can assign a code to it, probably using MATCH or VLOOKUP formulas, so ideally the data would look like this

    Postcode Postcode prefix Region code
    SW1Y6LR SW1Y 6 SW01
    SW21QW SW2 1 SW02
    SW22FB SW2 2 SW02
    SW23JH SW2 3 SW02
    SW24KM SW2 4 SW02
    SW25SC SW2 5 SW02
    SW31AZ SW3 1 SW03
    SW32QN SW3 2 SW03

    The data comes in two lots (postcodes and then the postcode prefix and region code data), so I'm wanting to find a formula that matches the postcode up with the postcode prefix, then allowing me to assign a region code to each postcode.

    The challenge is the postcode prefix varies in length and is a mix letters and numbers

    Does anyone know a solution to this please?

    Thanks for your help,

    PC

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,857

    Re: Matching with variable identifier (kind of)

    Please read the yellow banner at the top of this page on how to attach a file.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    03-12-2020
    Location
    UK
    MS-Off Ver
    365
    Posts
    12

    Re: Matching with variable identifier (kind of)

    No problem Alan, I've attached a file.
    Attached Files Attached Files

  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,452

    Re: Matching with variable identifier (kind of)

    In D2 then drag down:
    Please Login or Register  to view this content.
    The rest can be done with VLOOKUP
    Quang PT

  5. #5
    Registered User
    Join Date
    03-12-2020
    Location
    UK
    MS-Off Ver
    365
    Posts
    12

    Re: Matching with variable identifier (kind of)

    Hi Bebo, this is great, thank you! One more thing though, when I try to expand the table (the real set has about 10,000 rows) as below (only thing changed highlighted bold):

    =LOOKUP(2,1/COUNTIF(C2,SUBSTITUTE('Region codes'!$A$2:$A$10000," ","")&"*"),'Region codes'!$A$2:$A$10000)

    It returns a 0 result, do you know why this is and how to fix?

    Thank you,
    PC

  6. #6
    Registered User
    Join Date
    03-12-2020
    Location
    UK
    MS-Off Ver
    365
    Posts
    12

    Re: Matching with variable identifier (kind of)

    Hi Bebo, this is great, thank you! One more thing though, when I try to expand the table (the real set has about 10,000 rows) as below (only thing changed highlighted bold):

    =LOOKUP(2,1/COUNTIF(C2,SUBSTITUTE('Region codes'!$A$2:$A$10000," ","")&"*"),'Region codes'!$A$2:$A$10000)

    It returns a 0 result, do you know why this is and how to fix?

    Thank you,
    PC

  7. #7
    Registered User
    Join Date
    03-12-2020
    Location
    UK
    MS-Off Ver
    365
    Posts
    12

    Re: Matching with variable identifier (kind of)

    When I change the below (highlighted) section of the formula, it returns a 0 - I don't understand why

    =LOOKUP(2,1/COUNTIF(C2,SUBSTITUTE('Region codes'!$A$2:$A$25," ","")&"*"),'Region codes'!$A$2:$A$25)

  8. #8
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,452

    Re: Matching with variable identifier (kind of)

    Attach sample again with unmatching code, I guess some region codes are not in same format

+ 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] What kind of variable i am declaring?
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-21-2019, 07:09 AM
  2. [SOLVED] Find all matching values in two tables and return identifier
    By Nora Kro in forum Excel General
    Replies: 3
    Last Post: 08-17-2018, 10:48 AM
  3. Replies: 0
    Last Post: 02-09-2017, 01:03 PM
  4. [SOLVED] Matching emails based upon number identifier
    By Meltom in forum Excel General
    Replies: 6
    Last Post: 10-02-2013, 11:35 PM
  5. [SOLVED] Using A variable as a column identifier
    By lbren979 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-31-2013, 10:32 AM
  6. [SOLVED] Need help with merging rows by matching unique identifier.
    By lunatyck in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-31-2012, 11:59 AM
  7. cell matching...kind of..
    By Adam0414 in forum Excel General
    Replies: 1
    Last Post: 03-16-2010, 01:12 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