+ Reply to Thread
Results 1 to 11 of 11

Search cell for four letter code/s and return matching email/s.

  1. #1
    Registered User
    Join Date
    05-19-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    5

    Search cell for four letter code/s and return matching email/s.

    I'm wanting to use a formula or function that searches cells for four letter codes and returns any corresponding email assigned to that code in the table. I have a table with the codes and emails in them eg A1:B8 where column A=codes and B=emails.
    In the searched cells there can be:
    a) no codes
    b) one code or
    c) more than one code.
    In each instance I would want
    a) no email returned
    b) the one email for that code returned
    c) each email for each code returned.
    A VLOOKUP works well when there is no code or only one code in the cell but when there is more than one code only the first code/email is returned.
    I've attached an example document that shows an example of how the search works and how only the 1st code/email is returned.

    EXAMPLE EXCEL DOC.xlsx

    If anyone can help that'd be greatly appreciated.

  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,926

    Re: Search cell for four letter code/s and return matching email/s.

    Hi and welcome to the forum

    You havew shown some examples of what you have, and what its giving you, but I dont see any samples of when it does not give you what you want?
    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
    05-19-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Search cell for four letter code/s and return matching email/s.

    Hi FDibbins,

    Thanks for the welcome and quick response.
    Cell D7 in the example should display two emails for the two codes (EFGH & QRST) that are in C7
    Thanks,
    Tim

  4. #4
    Valued Forum Contributor
    Join Date
    12-14-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    439

    Re: Search cell for four letter code/s and return matching email/s.

    Quote Originally Posted by TimHerbert View Post
    Hi FDibbins,

    Thanks for the welcome and quick response.
    Cell D7 in the example should display two emails for the two codes (EFGH & QRST) that are in C7
    Thanks,
    Tim
    Hi TemHerber,
    You can try this UDF
    Please Login or Register  to view this content.
    with formula at E2:
    Please Login or Register  to view this content.

  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,926

    Re: Search cell for four letter code/s and return matching email/s.

    If you will only have 2 combinations, then you can use this, copied down...

    =VLOOKUP(C7,$A$2:$B$8,2)&IF(ISNUMBER(SEARCH(" ",C7,1))," "&VLOOKUP(MID(C7,SEARCH(" ",C7,1)+1,99),$A$2:$B$8,2),"")

    If you will have more han 2, it gets messy, but you need to add...
    " "&VLOOKUP(MID(C7,SEARCH(" ",C7,1)+1,99),$A$2:$B$8,2)
    but modify the search() function in each case (bolded) to search for the extra spaces

  6. #6
    Registered User
    Join Date
    05-19-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Search cell for four letter code/s and return matching email/s.

    Quote Originally Posted by FDibbins View Post
    If you will only have 2 combinations, then you can use this, copied down...

    =VLOOKUP(C7,$A$2:$B$8,2)&IF(ISNUMBER(SEARCH(" ",C7,1))," "&VLOOKUP(MID(C7,SEARCH(" ",C7,1)+1,99),$A$2:$B$8,2),"")

    If you will have more han 2, it gets messy, but you need to add...
    " "&VLOOKUP(MID(C7,SEARCH(" ",C7,1)+1,99),$A$2:$B$8,2)
    but modify the search() function in each case (bolded) to search for the extra spaces
    This works perfectly for two codes. Thanks a lot.
    I'm a little unclear as to what exactly it is I'm adding where if there are more than 2 codes to be found.
    If the maximum number of codes to find was 13 what would the final formula look like?

    Thanks so much for your help.

  7. #7
    Registered User
    Join Date
    05-19-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Search cell for four letter code/s and return matching email/s.

    Quote Originally Posted by huuthang_bd View Post
    Hi TemHerber,
    You can try this UDF
    Please Login or Register  to view this content.
    with formula at E2:
    Please Login or Register  to view this content.
    Hi huuthang,
    I tried this and it worked really well for the example sheet but when I tried it in my actual data it wasn't successful as I had to adjust the E2 formula to provide information from another sheet.

    Thanks,
    Tim

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Search cell for four letter code/s and return matching email/s.

    Quote Originally Posted by TimHerbert View Post
    If the maximum number of codes to find was 13 what would the final formula look like?
    In that case make use of code provided by huuthang_bd


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

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

    Re: Search cell for four letter code/s and return matching email/s.

    If the maximum number of codes to find was 13 what would the final formula look like?
    short answer...insane - refer to post #8

  10. #10
    Valued Forum Contributor
    Join Date
    12-14-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    439

    Re: Search cell for four letter code/s and return matching email/s.

    Quote Originally Posted by TimHerbert View Post
    Hi huuthang,
    I tried this and it worked really well for the example sheet but when I tried it in my actual data it wasn't successful as I had to adjust the E2 formula to provide information from another sheet.

    Thanks,
    Tim
    Hi Tim,
    Can you attach the file which the UDF not working?

    huuthang

  11. #11
    Registered User
    Join Date
    05-19-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Search cell for four letter code/s and return matching email/s.

    Quote Originally Posted by huuthang_bd View Post
    Hi Tim,
    Can you attach the file which the UDF not working?

    huuthang
    Hi huuthang,
    After having a play I've managed to get it working.
    Thank you very much for your help!

    Tim

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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