+ Reply to Thread
Results 1 to 18 of 18

Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate columns

  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    Queensland, Australia
    MS-Off Ver
    2016
    Posts
    35

    Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate columns

    I have a column of data (MyData) from which I need to extract multiple keywords/phrases from each row. Please see attached example.

    The keywords/phrases from MyDefinedListA may/may not exist in the string, but will only appear once if it does.
    The keywords/phrases from MyDefinedListB & MyDefinedListC - may/may not exist in the string, and could appear more than once.

    I'm trying to extract the Nth occurrence in a separate column for each word in the MyDefinedListB & MyDefinedListC - there should be no more than 4 occurrences in total.

    The attached example is how I would like the result to look (I have limited it to 2 occurrences in this example but it can range up to 4 in either of the MyDefinedListB & MyDefinedListC named ranges):

    I have tried to work this out but am having very little success.

    Any help would be really appreciated!
    Attached Files Attached Files
    Last edited by darls15; 08-24-2019 at 10:04 PM.

  2. #2
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,496

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    I am unclear as to what you want as the result. You appear to have the words already, are you looking for TRUE or FALSE as to whether or not the word is in the text in col A?
    if you are looking for that then this will return TRUE or FALSE as to if the word in columns B2 through I2 are in A2... =IFERROR(ISNUMBER(SEARCH(B2,$A2)),"")

    If you simply want to find a specific word, then substitute the word like "Day Time" for B2 like this... =IFERROR(ISNUMBER(SEARCH("day time",$A2)),"") and it will either return TRUE or FALSE.
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  3. #3
    Registered User
    Join Date
    06-26-2014
    Location
    Queensland, Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    Hi Sam, the data in Columns E:I is where the formula will go and an example of what results I need returned. Column A is the data I'm querying, Column B:D are the lists of keywords/phrases which are my defined named ranges and what the formula uses when querying Column A.

    Does this make sense?

    Thanks

  4. #4
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,496

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    Ok, well then put this in cell E2 =IF(ISNUMBER(SEARCH(B2,$A2))=TRUE,B2,"") and drag toward the right. BUT, you are looking at three columns with B through D while dragging it to the right in 5 columns so it will run out of reference cells when it gets to col H as it will then be pointing at cell E2 which is the result of the first formula.

  5. #5
    Registered User
    Join Date
    06-26-2014
    Location
    Queensland, Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    My apologies, I don't think I'm explaining this so well. I'll try again.

    I have an array formula, which when put in Cell E2, the result is "Day time"...
    =IFERROR(INDEX(MyDefinedListA,MATCH(1,(--(NOT(ISERR(SEARCH(MyDefinedListA,A2))))),0)),"")

    I need a similar formula, that when put into Cell F2, the result is "Sarah" (the 1st keyword in A2 which matches the keyword/phrase in defined list, MyDefinedListB)

    Then when put into Cell G2, the result is "Kevin" (the 2nd keyword in A2 which matches the keyword/phrase in defined list, MyDefinedListB)

    And again a formula for H2 and I2 where the 1st and 2nd keyword/phrase in cell A2 matches the keyword/phrase in defined list, MyDefinedListC) H2="class" and I2="class"

    If there's no match, the cell is left blank.

  6. #6
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,496

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    I'm missing what you are trying to do as to what is different than what I gave you. That array formula you have is simply looking at what is in B2 and if it is in A2 it is pulling it out. Lois is in C2 but not in A2 it is returning a blank when repointed at that table (col C). What I gave you is not an array and will look at what is in B2 and if it matches what is in A2 it will return that, otherwise it will be blank. It will repeat that for C2, if Lois isn't in A2 it will return blank.

    Right now we (my formula and yours) are working off the same row. Are you saying that, if the formula goes to the right from E2 into F2 and looks at Lois in C2 but doesn't find it in A2, you want the formula to index down a row staying in C but going to C3 to see if Kevin is in A2 and then returning that?

  7. #7
    Registered User
    Join Date
    06-26-2014
    Location
    Queensland, Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    Hi Sam, this is a complex scenario for me to explain, so thank you for your patience.

    I think what I'm not getting across is that MyDefinedListA ($B$2:$B$5), MyDefinedListB ($C$2:$C$5) and MyDefinedListC ($D$2:$B$11) are defined ranges, not a single cell reference.

    So to explain further and just looking at the data in A2 for the moment.

    I already have the formula to extract the word/phrase from A2 that matches a word\phrase in $B$2:$B$5 - in this instance it's "Day time". This formula is placed in E2 and copied down to E13. There will only ever be one instance of the word in a cell (A2:A13) so the formula for E2 isn't a problem. The formula I'll use here is =IFERROR(INDEX(MyDefinedListA,MATCH(1,(--(NOT(ISERR(SEARCH(MyDefinedListA,A2))))),0)),"") as in my last post.

    Where I'm having trouble with the formula in the cells F2, G2, H2 and I2.

    In F2 I need to extract the word\phrase from $C$2:$C$5 (Lois, Kevin, Joe, Sarah) that appears 1st in cell A2. The 1st word sighted in A2 from the $C$2:$C$5 list would be "Sarah". In G2 I need the 2nd word sighted in A2 which would be "Kevin".

    The formula in H2 would be the same as F2 but referencing the range $D$2:$D$11 (hamburgers, bag, cat ,ice cream ,computer class etc.) instead of $C$2:$C$5. This would then return the 1st word sighted in A2 from the $D$2:$D$11 range, which is "class". Lastly, I2 would be the same as G2, just the change in reference again to $D$2:$D$11 to return the 2nd word sighted in A2 matching in the $D$2:$D$11 range, which is also "class".

    I hope this is a little clearer as to what I'm trying to achieve.

    Thanks again for your help, it is really appreciated.

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

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    Are you still using Excel 2010?
    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.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  9. #9
    Registered User
    Join Date
    06-26-2014
    Location
    Queensland, Australia
    MS-Off Ver
    2016
    Posts
    35
    Hi, yes I am
    Last edited by AliGW; 08-25-2019 at 03:50 AM. Reason: Please don't quote unnecessarily!

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

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    That's a shame.

    Is the layout of the data a must? There may be easier ways to do what you want if you have some flexibility.

  11. #11
    Registered User
    Join Date
    06-26-2014
    Location
    Queensland, Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    I'm sorry, I got that wrong, I've actually got Excel 2016.
    Last edited by darls15; 08-25-2019 at 06:35 AM.

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,488

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    Ah, OK. Could you please update your user profile to reflect this?

    Are you able to answer the question in my last post?

  13. #13
    Registered User
    Join Date
    06-26-2014
    Location
    Queensland, Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    As for the layout, it's pretty much how I need the end result to look ... apart from the lookup columns. Can you please explain what you mean in terms of being flexible with the layout? Thanks

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,488

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    The problem is the number of columns - how far across the page do you anticipate going? It is not good to create something in this format that requires horizontal scrolling - the human eye copes better with vertical scrolling.

    I was thinking that there might be a PowerQuery solution, buy I have run out of time for testing this morning - sorry.

  15. #15
    Registered User
    Join Date
    06-26-2014
    Location
    Queensland, Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    I probably wouldn't need to extend beyond the number of columns as shown in the example as there wouldn't be too many rows that go beyond 2 occurrences for each defined range. Thanks AliGW

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

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    The named ranges need to be coincident with the non-blank cells. I have adjusted them manually. It can be done automatically, if they're going to change a lot.

    If there are NEVER going to be items in list B that are also on list A and similarly, none in C that are also in B, then this will work. If items in B can also occur in A, we'll need a blank column (which can be hidden) to make life easier.

    E2, copied down:
    =IFERROR(LOOKUP(1000,SEARCH(MyDefinedListA,A2),MyDefinedListA),"")

    F2, copied across and down:
    =IFERROR(LOOKUP(1000,SEARCH(MyDefinedListB,SUBSTITUTE($A2,E2,"",1)),MyDefinedListB),"")

    G2:
    =IFERROR(LOOKUP(1000,SEARCH(MyDefinedListC,SUBSTITUTE($A2,G2,"",1)),MyDefinedListC),"")

    Note the result in H7. If you're OK with it, replace computer class in your keyword list with computer. It will then find computer and class as separate results. Would that work??
    Attached Files Attached Files
    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.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  17. #17
    Registered User
    Join Date
    06-26-2014
    Location
    Queensland, Australia
    MS-Off Ver
    2016
    Posts
    35

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    Hi Glenn, I can't thank you enough! I've tried your formula out with my "real" data and it works brilliantly. Thank you so much!

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

    Re: Extract 1st,2nd occurrence of keywords in string, from named ranges, into separate col

    You're welcome.



    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It'd also be appreciated if you were to click the Add Reputation button at the foot of any of the posts of all members who helped you reach a solution.

+ 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] Named Ranges between two separate workbooks
    By Aquarock in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-09-2019, 12:56 PM
  2. [SOLVED] Filter or Lookup Keywords in Separate Columns
    By MKTGCLOUD in forum Excel General
    Replies: 8
    Last Post: 11-26-2018, 06:03 AM
  3. Extract String After Second Occurrence of Delimiter
    By pwyller in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-27-2016, 08:56 AM
  4. [SOLVED] Stripping Keywords out of a text string and placing into relevant columns
    By seanpcorbett1 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-12-2016, 10:25 AM
  5. [SOLVED] How to extract named ranges for each cell
    By alice2011 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-18-2015, 01:43 PM
  6. Replies: 12
    Last Post: 08-14-2014, 11:37 AM
  7. Replies: 11
    Last Post: 12-04-2012, 02:56 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