+ Reply to Thread
Results 1 to 13 of 13

Extracting specific text from 1 column to another where they can be more than 1 occurence

  1. #1
    Registered User
    Join Date
    02-27-2021
    Location
    Sydney Australia
    MS-Off Ver
    Microsoft 365
    Posts
    5

    Extracting specific text from 1 column to another where they can be more than 1 occurence

    Hi
    I'm hoping someone can help me with how to extact specific text (text that follows '#'), from one column (text, with varying length). In the attached example, I have worked out (with thanks to whoever posted that to the web) how to extract the first occurence (shown in Column D) from Column C. That solves my problem where there is only one occurence (or none, when i get an error 'VALUE!' messsage).

    But i can't work out how to extract subsequent examples of '#[text]. If i can recreate Column C without the extracted text now in Column D (e.g. Col E=Col C minus Col D), I could replicate the previous process and extract any second #[text] again, and continue that process till I get no more cells without an occurence of #text]. That's a bit fiddly, but i can easily do that. Or someone smart will undoubtedly have a simpler way to do it....

    So can someone suggest how to either
    a) Look in Column C, search for text including '#', put the first occurence of '#[text] in Col D, the next in Col E, etc, until there are no more occurences of '#', (that would be my provided solution, OR

    b) tell me how to omit specified selected text (i.e. first extraction of #[text]) from a cell, so i can re-run the extraction formula to search for additional occurrences of #[text]t?

    I hope that is clear... thank you very much in advance if you have a suggestion...
    regards
    Sue
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,577

    Re: Extracting specific text from 1 column to another where they can be more than 1 occure

    In D2 then copied across

    =TRIM(MID(SUBSTITUTE($C2,"#",REPT(" ",200)),COLUMNS($D2:D2)*300,300))
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

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

    Re: Extracting specific text from 1 column to another where they can be more than 1 occure

    I think you made a mistake there... shouldn't it be:

    =TRIM(MID(SUBSTITUTE($C2,"#",REPT(" ",300)),COLUMNS($D2:D2)*300,300))


    not 200....
    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

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,577

    Re: Extracting specific text from 1 column to another where they can be more than 1 occure

    Yes. It is a mistake. Thanks you have corrected the mistake.
    Correct formula

    =TRIM(MID(SUBSTITUTE($C2,"#",REPT(" ",300)),COLUMNS($D2:D2)*300,300))
    Attached Files Attached Files
    Last edited by kvsrinivasamurthy; 02-27-2021 at 05:16 AM.

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,073

    Re: Extracting specific text from 1 column to another where they can be more than 1 occure

    Another option
    =IFERROR(FILTERXML("<l><m>"&SUBSTITUTE(REPLACE($C2,FIND("http",$C2),200,""),"#","</m><m>#")&"</m></l>","//m["&COLUMNS($C2:D2)&"]"),"")
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    02-27-2021
    Location
    Sydney Australia
    MS-Off Ver
    Microsoft 365
    Posts
    5

    Re: Extracting specific text from 1 column to another where they can be more than 1 occure

    You people are soooo good, thank you...
    I am most of the way to solving my problem, thank you...
    I've tried both suggested formulae (thank you) on the test sheet i sent you (I am sooo sorry that i sent you
    the full spreadsheet, rather than the single tab I meant to send), and on a larger test.

    I have also tested the suggested formulae on two forms of the text I am examining (with and without cleanup
    to remove weird formatting, but that doesn't seem to make a difference). The first suggested formula works very
    well, except there are some weird errors (see coloured cells in Col E of the new attached spreadsheet). Can you see
    the reason for those errors? The second formula works in some cases, but unpredictably doesn't register some
    #[plustext] at all (you can see the result in the new attached spreadsheet, so I am trying for the first formula,
    though any suggestions on the second forumula again, very gratefully accepted!

    The second issue (which I can work around if I have to) is that the formula is copying anything after the last
    hashtag extracted into the column, so I first get the term i want to extract (the #[Plustext], but then some
    irrelevant trailing text. I can work around that if necessary (my best solution is splitting columns,
    but would any of you Excel Wizzes have any suggestion for that?

    Many thanks for any suggestions. (And if it makes you feel better, I am not making any money out of this. I'm
    an academic working on a project to help a junior academic!
    regards
    Sue
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,577

    Re: Extracting specific text from 1 column to another where they can be more than 1 occure

    Here is the changed formula. It works for any length of text.
    Pl see file . I have applied the formula
    For D2 then copied across.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,577

    Re: Extracting specific text from 1 column to another where they can be more than 1 occure

    How to you find which is the unwanted trailing text.

  9. #9
    Registered User
    Join Date
    02-27-2021
    Location
    Sydney Australia
    MS-Off Ver
    Microsoft 365
    Posts
    5

    Re: Extracting specific text from 1 column to another where they can be more than 1 occure

    Dear Kvsrinivasamurthy
    Thank you again! You are a genius... That is almost solved! I had two weird answers (Cells D721 and D894), which recorded a few characters, but I think that's because the character length was longer than 300 characters. So i changed the 300 in your formual to 350. So I now have:
    =TRIM(MID(SUBSTITUTE($C2,"#",REPT(" ",CEILING(LEN($C2),350))),COLUMNS($D2:D2)*CEILING(LEN($C2),350),CEILING(LEN($C2),350)))

    That seems to work perfectly, except for the trailling text (which follows the last detected hashtag). I think you asked in your second message what is the unwanted trailing text? It's everything except the #[PlusText] word. Do you know how to remove that? If you don't, I will split the columns where it occurs, so i can remove it, but it would be perfect if I could just remove it automatically (e.g. by pasting the # back in at the start of the cell, and then removing everything that doesn't start with a '#'. Do you know if that is possible?

  10. #10
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,577

    Re: Extracting specific text from 1 column to another where they can be more than 1 occure

    With file and example explain about unwanted text.

  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 2403
    Posts
    43,984

    Re: Extracting specific text from 1 column to another where they can be more than 1 occure

    This covers all the awkward ones in your sample, so far:

    =IFERROR(FILTERXML("<A><B>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($C2,""," "),"&","and"),","," "),CHAR(10)," ")," #","</B><B>#")," ","</B><B>")&"</B></A>","//B[contains(., '#')]["&COLUMNS($D2:D2)&"]"),"")

    in D2, copied across and down.

    NOTE: Use the formula IN THE FILE, not the one above, as the EF has changed the formatting of ONE character (in red) above!!
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    02-27-2021
    Location
    Sydney Australia
    MS-Off Ver
    Microsoft 365
    Posts
    5

    Smile Re: Extracting specific text from 1 column to another where they can be more than 1 occure

    Glenn, Thank you sooo much! (You should have heard me when i looked at it, saying 'Yes! Yes! Yes!'
    That is beautiful, and is going to save me so much time and stress... I'm really grateful. At the risk of
    giving you too much information, my brother was very, very good at coding in Excel (though not nearly in your category),
    but died (too young)a few years ago. When I was first trying to solve this problem, I thought 'I can't go to Frank!'
    He would have loved your solution, and with your solution, I can think of him and smile. Thank you again!

    I will now try to find where to mark this closed, but if I can't find it, as moderator, I am sure you can close it on my behalf
    regards
    Sue

  13. #13
    Registered User
    Join Date
    02-27-2021
    Location
    Sydney Australia
    MS-Off Ver
    Microsoft 365
    Posts
    5

    Re: Extracting specific text from 1 column to another where they can be more than 1 occure

    Glenn, I am so sorry, I can't find where to mark this as solved! Can you please do it for me? (I assume you can do that...) And I hope it makes you feel good to help people like me. It should, sinc eyou have just about made my day, and that of my junior researchers!

+ 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. Nth Occurence VBA returning specific column
    By excelnewbie3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-07-2015, 12:32 PM
  2. Extracting specific text from a column and copying to another sheet or workbook
    By Noobcake in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-04-2013, 09:29 AM
  3. Replies: 1
    Last Post: 01-21-2013, 01:21 PM
  4. [SOLVED] Extracting specific part of the text string to another column
    By ssanjju in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 01-20-2013, 07:20 PM
  5. Extracting data from column based on specific criteria and pasting into new column
    By vanvalkenburg in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-14-2012, 10:26 PM
  6. Extracting Specific Text
    By jdh3 in forum Excel General
    Replies: 5
    Last Post: 07-11-2011, 12:56 PM
  7. [SOLVED] Find first occurence of specific data in a column.
    By Ben in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-24-2005, 11:06 AM

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