+ Reply to Thread
Results 1 to 41 of 41

Partial VLookup with Multiple Matches

  1. #1
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Partial VLookup with Multiple Matches

    Dear Excel Experts,

    I am new to this forum and am very happy to have discovered it.
    This is what i am trying to do and tearing my hair. Hopefully, someone can give me a solution

    I have one column (A) with a sentence of multiple words.
    I have another table with two columns (C & D) with sentences containing multiple words.

    I need to match ANY of the words in column A with ANY of the words in Column C and Return the values in Column D.
    Another hing. If there are more than one matches, then it needs to return all the values comma separated

    Is this possible?

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Partial VLookup with Multiple Matches

    Lots of things are possible. Nothing is possible with just a pile of words.

    A picture is worth 1,000 words. An Excel sheet is worth 1,000 non-editable pictures.

    Please read the yellow banner about sample worksheets, at the top of the screen. Act on its guidelines and post a SMALL sample sheet complete with an explanation and some expected results.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  3. #3
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    Apologies Glenn. And i really appreciate your offer to help. Here is the excel file. I have removed my formulae and replaced them with the expected results (manually).
    Attached Files Attached Files

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Partial VLookup with Multiple Matches

    With Excel 2007, your options are a bit limited!! Please answer ALL 3 questions clearly.



    1. Can I use VBA?

    2. If VBA is not an option, can I use a helper column?

    3. If a helper column is not an option (and remember Excel has 16,000 or more columns... so there are plently to spare), what is the MAXIMUM number of references that can be associated with one key word?

  5. #5
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    1. I would like to avoid VBA if possible
    2. Helper column is absolutely OK
    3. Maximum would be 10

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Partial VLookup with Multiple Matches

    I've just noticed a complication... sack hook... this may throw my plans into a mess.

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Partial VLookup with Multiple Matches

    No. I think I'm unable to take this forward. Your best option is probably VBA. If that is OK, I will delete the current replies and I will move the thread to the VBA sub-forum where the VBA wizards will get it to work.

    Please let me know.

  8. #8
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    I understand. Ignore sack hook please. I will work around this limitation

  9. #9
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    Ok. Let's try the VBA route

  10. #10
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,264

    Re: Partial VLookup with Multiple Matches

    Please Login or Register  to view this content.
    =wMatch(G4)
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  11. #11
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: Partial VLookup with Multiple Matches

    Or with the aid of several helper columns (probably don't need them all and almost definitely can be tidied up).

    1. Separate the words into columns
    2. Use this array (CSE) formula to find every occurrence of each word

    Please Login or Register  to view this content.
    3 then finally a textjoin.

    see attached.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    Hello John .. Need your help again. I tried modifying the code to make this happen and it did not work. I was trying to move B3:C to a different sheet. Basically, keep the reference (B, C) and the lookup & result (G, H) need to be on different sheets. is that possible?

  13. #13
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,264

    Re: Partial VLookup with Multiple Matches

    Yes but please post a file with your expected output: the current code is a FUNCTION so it cannot reference another sheet so will need to changed to a SUBROUTINE.

  14. #14
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    Thanks John.

    For john.png

  15. #15
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,264

    Re: Partial VLookup with Multiple Matches

    Please Login or Register  to view this content.
    Change highlighted if you want different cell
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    Thank you so much John !!

  17. #17
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    John .. hi
    I get this error whenever i enter a word that is NOT present under lookup (Sheet2, Column G)

    Error.png

  18. #18
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    Everything is OK as long as the words entered under the lookup column (in sheet2) are present in Sheet1

  19. #19
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,264

    Re: Partial VLookup with Multiple Matches

    change this

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    Thanks Again John

  21. #21
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,264

    Re: Partial VLookup with Multiple Matches

    You're very welcome and thank you for the feedback (rep).

  22. #22
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    Hi John .. One more issue. Hopefully, it is the last . I tried tinkering with the code, but i seem to be breaking things than fixing it. Anyways, right now, it is matching words that are part of other words. It should only match whole words. This picture should explain


    Full word matching.png

  23. #23
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,264

    Re: Partial VLookup with Multiple Matches

    You know pictures are of little use not least because they are not readable (with my old eyes!).

  24. #24
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,264

    Re: Partial VLookup with Multiple Matches

    Try

    Please Login or Register  to view this content.
    Attached Files Attached Files

  25. #25
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    Understood Here is the excel file with notes. On sheet2. Appreciate it
    Attached Files Attached Files

  26. #26
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Partial VLookup with Multiple Matches

    I had this after editing John's code slightly (hope you don't mind John).

    Please Login or Register  to view this content.

  27. #27
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: Partial VLookup with Multiple Matches

    I was think that my solution will be solve your request (if you don't mind to use a lot of helper cells).
    But ..... it didn't work with 'Sack hook'
    Sorry

    Regards.


    Note : If you allow to use so many helper cells, it's might work.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by menem; 04-05-2022 at 04:42 AM. Reason: Add file & Note

  28. #28
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Partial VLookup with Multiple Matches

    John, I did a similar approach to you at first (adding " " to start and end actually, what you did is neater) but then realised it misses some matches from the example, e.g. it does not match "someone" with "someone's", because it is looking for "someone ".

  29. #29
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    That's perfect John. Thnks again. I am just curious about one thing. If i add a space after the word (lookup), then it picks up all the cells. The word "So" and "So " gives different results.
    Thanks Nick and Menem for contributing.

    regards

  30. #30
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Partial VLookup with Multiple Matches

    Oops, my code doesn't work at all. Haha. But, question for OP - do you want to match "someone" with "someone's"? This makes it very difficult to only match whole words.

  31. #31
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,264

    Re: Partial VLookup with Multiple Matches

    @nick/guna_shekar: the "issue" is that some (most) matches are partial (like "someone" which was picked up in the original) and exact for single letters which only applies to the letters "I" and "A" in standard English. I realised this when I compared the last results with my original solution.

    I suppose a test could be added for the latter (single letter) and leave the original INSTR partial logic. and then you have the "so" example ! (and "to" etc)

    Another of these tricky text matching exercises !
    Last edited by JohnTopley; 04-05-2022 at 04:33 AM.

  32. #32
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    John .. You are right. This gets tricky. Because, there are also words with just two letters like "it". So, "IT" is a match. But, it should not pick "WITH". Of course, "Someone" and "Someone's" should be the same. But, the code can get complicated - i think.

  33. #33
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Partial VLookup with Multiple Matches

    Quote Originally Posted by guna_shekar View Post
    That's perfect John. Thnks again. I am just curious about one thing. If i add a space after the word (lookup), then it picks up all the cells. The word "So" and "So " gives different results.
    Thanks Nick and Menem for contributing.

    regards
    The problem here is that a Split of "i " returns "i" and "", the latter string then gets matched with everything. I think you could get round it by replacing:

    Split(x, " ")

    with

    Split(Trim(x), " ")

  34. #34
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: Partial VLookup with Multiple Matches

    Please see my attatched file above. If you don't mind to use helper cells.

    Regards.
    Attached Images Attached Images
    Last edited by menem; 04-05-2022 at 04:43 AM.

  35. #35
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,264

    Re: Partial VLookup with Multiple Matches

    'guna: if "someone" and "someone's" are to be treated as separate words then ALL matches are exact matches.

  36. #36
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    Quote Originally Posted by JohnTopley View Post
    'guna: if "someone" and "someone's" are to be treated as separate words then ALL matches are exact matches.
    That is correct John.

  37. #37
    Registered User
    Join Date
    02-23-2022
    Location
    bangalore
    MS-Off Ver
    2007
    Posts
    27

    Re: Partial VLookup with Multiple Matches

    Quote Originally Posted by nick.williams View Post
    The problem here is that a Split of "i " returns "i" and "", the latter string then gets matched with everything. I think you could get round it by replacing:

    Split(x, " ")

    with

    Split(Trim(x), " ")
    Yes. This works. Perfect !!

  38. #38
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Partial VLookup with Multiple Matches

    Ok, so we have something that basically works if there are no special characters. To deal with other cases it depends how you want them to be treated? There's ways to do it but you probably need to deal with all cases separately. The trouble is that I guess it's hard to think of every possible case in advance.

    e.g. full stops, do you want to ignore them regardless, or only if they are the last character of the string, or only if they are at the end of a word (not sure why this would happen but e.g. match (test" with "test." but not "te.st"

    Similarly with apostrophes, if you just want to ignore everything after the apostrophe that's fine, but would you potentially have them in your lookup words as well?

    This is all do-able but needs allowing for and it's hard to know for sure what your desired outcome is.

    NB my code above works nicely (apart from special characters) if you replace:

    If InStr(1, UCase(u(k)), UCase(t(j))) Then

    with

    If UCase(u(k)) = UCase(t(j)) Then

  39. #39
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: Partial VLookup with Multiple Matches

    If you prefer UDF , please try

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by menem; 04-05-2022 at 06:04 AM. Reason: re-correct udf.

  40. #40
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,264

    Re: Partial VLookup with Multiple Matches

    Please Login or Register  to view this content.
    logic:

    If "lookup" is a single word e.g, I , To, So then it does an exact match on each word in the table on Sheet1

    If "kookup" is 2 or more words, it does a match on the "phrase" first: if no match then it matches each individual word.

    If a word appears more than once in the list "No pain, no gain" then it is recorded once only.

    "someone" and "someone's" are treated as different
    Attached Files Attached Files

  41. #41
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: Partial VLookup with Multiple Matches

    In case you want these are the same

    someone , someone's
    it, it's
    or any other of 's

    you may use helper column with SUBSTITUTE( old_cell , "'s" , "" )
    then use my UDF's from those helper cells.

    Regards.

+ 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] vlookup with multiple partial matches
    By richx in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-09-2019, 11:23 AM
  2. Vlookup Partial Matches HELP
    By ramanm in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-20-2018, 07:46 AM
  3. vlookup to find partial matches
    By chris789 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-17-2018, 02:30 AM
  4. Help with looking up Partial text multiple matches
    By cceze in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-21-2016, 01:06 PM
  5. [SOLVED] Multiple partial matches
    By Grinfactor in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-28-2014, 01:15 PM
  6. Replies: 6
    Last Post: 08-16-2013, 08:46 AM
  7. Variation of VLOOKUP that returns all partial matches
    By anthonyle in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 03-14-2013, 12:40 AM

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