+ Reply to Thread
Results 1 to 17 of 17

Multiple matches in a cell separated by line break

Hybrid View

  1. #1
    Registered User
    Join Date
    04-11-2020
    Location
    Europe
    MS-Off Ver
    365
    Posts
    30

    Multiple matches in a cell separated by line break

    Dear excel community,

    I am facing the following problem to solve. In the range F2:G4 I have a list of countries with corresponding IDs. In column A I have quite random strings that might contain name of a country or countries. My task is to find a match in that string using F2:F4 as a source and bring the IDs of matching countries separated by a line break in a cell in column B.

    Country names are only given as 1 word starting with capital letter or all-capital abbreviations, such as RSA (Republic of South Africa). As well, different separators might be used for input string. Most commonly ',' or ' ' or ';'.

    Would appreciate a lot some suggestions

    Capture.JPG

    Best regards,
    P
    Attached Files Attached Files
    Last edited by Paulius03; 01-22-2021 at 05:45 AM.

  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: Multiple matches in a cell separated by line break

    In your real data are the "countries" always just one word? The only logic in determining the order in which a "country" appears seems to be the capital letter. If you have multi-capitalised names, like El Salvador... that approach won't work.
    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
    04-11-2020
    Location
    Europe
    MS-Off Ver
    365
    Posts
    30

    Re: Multiple matches in a cell separated by line break

    Hi Glenn,

    Thanks. I would say that the order is not critical. The most important thing is getting and showing the matching countries. I have changed the attachments now to reflect that.
    Last edited by Paulius03; 01-22-2021 at 05:08 AM.

  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: Multiple matches in a cell separated by line break

    Determining the order of the countries IS critical. Once you know that Russia is in the nth position out of Y positions, in a cell; you can extract the appropriate number.

    Of course, if there is ALWAYS at least one instance of the coutnry appearing in a cell ON ITS OWN, then there is no problem at all. However, since yoou have asked this question, I assume that this cannot be guaranteed.

    So, please answer my Q in my previous post.

  5. #5
    Registered User
    Join Date
    04-11-2020
    Location
    Europe
    MS-Off Ver
    365
    Posts
    30

    Re: Multiple matches in a cell separated by line break

    There are multi-capitalized names, such as South Africa.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,007

    Re: Multiple matches in a cell separated by line break

    ... but no such examples in your sample file.

    Your sample data needs to reflect the true data in every facet.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  7. #7
    Registered User
    Join Date
    04-11-2020
    Location
    Europe
    MS-Off Ver
    365
    Posts
    30

    Re: Multiple matches in a cell separated by line break

    To simplify the problem I will edit my original post saying that country names are only 1 word or all-capital abbreviations, such as RSA (Republic of South Africa).

    Quote Originally Posted by Glenn Kennedy View Post

    Your file suggests that you can have countries strung together with NO separator like this: ChinaRussiaBrazil
    is that REALLY the case?
    This is not highly likely but there is for sure not one specific separator that will be used in the strings. It will most probably be ',' or ' ' or ';'.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,007

    Re: Multiple matches in a cell separated by line break

    Quote Originally Posted by Paulius03 View Post
    There are multi-capitalized names, such as South Africa.
    And then ...

    Quote Originally Posted by Paulius03 View Post
    To simplify the problem I will edit my original post saying that country names are only 1 word or all-capital abbreviations, such as RSA (Republic of South Africa).
    Too many contradictions for me. It's really important to be ABSOLUTELY CLEAR about the nature of your data - saying one thing and then the opposite almost suggests that you are not clear yourself, so how can we really hope to address the problem properly for you?

  9. #9
    Registered User
    Join Date
    04-11-2020
    Location
    Europe
    MS-Off Ver
    365
    Posts
    30

    Re: Multiple matches in a cell separated by line break

    Based on the inputs of other members of the forum I made some adjustments to my initial problem conditions. Sorry for the confusion, but what should I do if there is a change? Should I create a new thread?
    Last edited by Paulius03; 01-22-2021 at 07:25 AM.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,007

    Re: Multiple matches in a cell separated by line break

    Quote Originally Posted by Paulius03 View Post
    Based on the inputs of other members of the forum I made some adjustments to my initial problem conditions. Sorry for the confusion, but what should I do if there is a change? Should I create a new thread?
    NO! Do what was suggested earlier and add the changes to a new post to the thread - that way, things remain chronological. Also, you can attach an updated file to the correct post chronologically.

  11. #11
    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: Multiple matches in a cell separated by line break

    Depending on your answer to the next question... this may be impossible (or at least beyond my ability).

    Your file suggests that you can have countries strung together with NO separator like this: ChinaRussiaBrazil

    is that REALLY the case?

  12. #12
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: Multiple matches in a cell separated by line break

    Please try

    Formula: copy to clipboard
    =--MID(SUBSTITUTE(VLOOKUP("*"&F2&"*",$A$2:$B$6,2,),CHAR(10),REPT(" ",99)),MATCH(1,FREQUENCY(FIND(F2,VLOOKUP("*"&F2&"*",$A$2:$A$6,1,)),SEQUENCE(99)/(ABS(CODE(MID(VLOOKUP("*"&F2&"*",$A$2:$A$6,1,),SEQUENCE(99),1))-77.5)<13)),)*99-98,99)
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    04-11-2020
    Location
    Europe
    MS-Off Ver
    365
    Posts
    30

    Re: Multiple matches in a cell separated by line break

    Quote Originally Posted by Bo_Ry View Post
    Please try

    Formula: copy to clipboard
    =--MID(SUBSTITUTE(VLOOKUP("*"&F2&"*",$A$2:$B$6,2,),CHAR(10),REPT(" ",99)),MATCH(1,FREQUENCY(FIND(F2,VLOOKUP("*"&F2&"*",$A$2:$A$6,1,)),SEQUENCE(99)/(ABS(CODE(MID(VLOOKUP("*"&F2&"*",$A$2:$A$6,1,),SEQUENCE(99),1))-77.5)<13)),)*99-98,99)
    Hi Bo_Ry,
    Not sure if I get your solution. The desired result is what we see in the cells B2:B6 in my original post.

  14. #14
    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: Multiple matches in a cell separated by line break

    Like i said... beyond my ability!!

  15. #15
    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: Multiple matches in a cell separated by line break

    You should NOT edit attachments AFTER replies have been received... it makes the replies unintelligible. Add any updated attachments in a new post in the same thread.

  16. #16
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: Multiple matches in a cell separated by line break

    Try at B2

    =TEXTJOIN(CHAR(10),,SORTBY(REPT($G$2:$G$5,ISNUMBER(SEARCH($F$2:$F$5,A2))),SEARCH($F$2:$F$5,A2)))
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    04-11-2020
    Location
    Europe
    MS-Off Ver
    365
    Posts
    30

    Re: Multiple matches in a cell separated by line break

    Quote Originally Posted by Bo_Ry View Post
    Try at B2

    =TEXTJOIN(CHAR(10),,SORTBY(REPT($G$2:$G$5,ISNUMBER(SEARCH($F$2:$F$5,A2))),SEARCH($F$2:$F$5,A2)))
    Seems to be working exactly how I wanted. Thank you!

+ 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. Removing multiple line breaks into single line break
    By anonymous321 in forum Excel General
    Replies: 7
    Last Post: 12-02-2020, 08:22 PM
  2. Replies: 4
    Last Post: 10-21-2020, 11:42 PM
  3. Replies: 4
    Last Post: 05-30-2018, 01:03 PM
  4. [SOLVED] Color lines within the same cell separated by line break
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-27-2018, 10:38 PM
  5. Replies: 5
    Last Post: 05-21-2013, 12:46 PM
  6. [SOLVED] Break cell into multiple lines by line break
    By Chia in forum Excel General
    Replies: 1
    Last Post: 08-20-2006, 01:40 AM
  7. Replies: 2
    Last Post: 06-14-2005, 02:05 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