+ Reply to Thread
Results 1 to 18 of 18

Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell value

  1. #1
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell value

    Experts:

    I need some assistance with either a) creating a custom-formula or b) using some VBA or macro which will extract all *entire* words that include an underscore ("_") in a cell.

    The cell values include carriage returns as well as duplicate occurrences of a particular keyword. Below shows and example of the raw data, the output of the keywords (w/ duplicates) as well as the string output without duplicates.

    Ideally, I would like to get to the output of the "2nd string" (w/o duplicates). Also, each "found keyword" should be separated by a semi-colon (or comma).

    My question: How can the output below accomplished via a formula or VBA? I have included a sample XLS containing 3 different example strings (with different lengths) and their associated outputs.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by skydivetom; 02-22-2021 at 04:19 PM.

  2. #2
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    Give this macro a try...
    Please Login or Register  to view this content.
    Last edited by Rick Rothstein; 02-22-2021 at 05:33 PM.

  3. #3
    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,418

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    Administrative Note:

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)
    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.

  4. #4
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    Rick -- wow... your solution is very, very close...

    I did a compare between my manual output and the macro ouput. Here's what I noted.

    1. The macro is case sensitive... that is, "pers_1st_line_supervisor" AND "PERS_1ST_LINE_SUPERVISOR" was output by the macro. Is there a way we can ignore the macro being case-sensitive and, therefore, drop either "pers_1st_line_supervisor" OR "PERS_1ST_LINE_SUPERVISOR"?

    2. Also, for some reason, cell A2 also include the keyword "field_name". Unless I'm mistaking, it appears this word was not picked up by the macro. If so, do you know why that's the case?

    Standing by in hopes we can could it to remove case-sensitivity to get a distinct list regard of lower/upper case.

    Thank you,
    EEH

  5. #5
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    I apologize for cross-posting... I will ensure to only choose one forum the next time.

    https://www.mrexcel.com/board/thread...value.1162629/

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    I put my code back in its original message... that code is now case insensitive.

  7. #7
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    AliGW -- my apologies... I provided the link. Would you please re-post Rick's solution as well as my follow-up question. Thank you!

  8. #8
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    Quote Originally Posted by skydivetom View Post
    AliGW -- my apologies... I provided the link. Would you please re-post Rick's solution as well as my follow-up question. Thank you!
    I already restored my solution with the change you wanted (see Message #5 first).

  9. #9
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    Thank you, Rick... your solution is perfect. Final question... is there any chance you could include some comments as to, e.g, the ForLoop and With function "do" during the VBA. Always like to have some understanding as to how the code operates. THOUSAND THANKS IN ADVANCE!

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

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    Quote Originally Posted by skydivetom View Post
    AliGW -- my apologies... I provided the link. Would you please re-post Rick's solution as well as my follow-up question. Thank you!
    I’ve restored yours, but Rick’s was never removed.

    Cross posting is allowed, but only if you are completely upfront about it abd provide links. Rads the rules page, please. Thanks.

  11. #11
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    Quote Originally Posted by AliGW View Post
    I’ve restored yours, but Rick’s was never removed.
    I had removed it after I saw your Administrative Note message, then I restored it with the requested fix after the OP posted his link.

  12. #12
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342
    Rick -- thank you... the solution is perfect.

    In the event you didn't get a chance to see my last response, is there any chance you could help me better understand the solution by adding some comments?

    Thank you

  13. #13
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    Quote Originally Posted by skydivetom View Post
    ...is there any chance you could help me better understand the solution by adding some comments?
    See if this helps...
    Please Login or Register  to view this content.

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

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    Formula for Excel 2019
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    formula for MS365

    Formula: copy to clipboard
    Please Login or Register  to view this content.



    UDF

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

  15. #15
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    Rick - thank you so much for posting the comments... I truly appreciate it.

    Btw, I posted a follow-up question (for data cleanup) in another post. Here's the link... in case you might be willing to offer additional insights for the follow-up question.

    https://www.excelforum.com/excel-pro...ml#post5477387

  16. #16
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    Bo_Ry - I appreciate your feedback, too. I downloaded the example but... good stuff; however, I prefer using the built-macro. IMHO, it is much easier to view/modify vs. the very long formula.

    Thank you for offering an alternative solution though... 'much obliged.

  17. #17
    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,418

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

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

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  18. #18
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Re: Need a formula (or VBA) which extracts keywords containing an underscore "_" in cell v

    AliGW -- thank you for the reminder to close the post. Btw, I already provided kudos to Rick (added to his reputation).

+ 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. Replies: 3
    Last Post: 11-19-2020, 08:30 PM
  2. Replies: 4
    Last Post: 06-11-2017, 02:03 PM
  3. Replies: 2
    Last Post: 03-08-2015, 09:31 AM
  4. Trying to autofill certain "keywords" with a specific cell.
    By philroyjenkins in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-27-2014, 02:03 AM
  5. [SOLVED] Formula Needed to fill multiple cells with "No" when the word "No" is entered into a cell
    By excelteam777 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-09-2013, 05:36 PM
  6. [SOLVED] Using underscore ("_") with Cells().formula, to divide the code in multiple lines
    By Mayda89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2013, 03:42 PM
  7. [Solved] Why would an "_" Underscore be in a Formula?
    By sdingman in forum Excel General
    Replies: 4
    Last Post: 12-08-2011, 05: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