+ Reply to Thread
Results 1 to 10 of 10

Need to delete selected stings from cell content

  1. #1
    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,398

    Need to delete selected stings from cell content

    I have a list of alphanumeric strings.

    Starting Point

    The cat sat on the mat.
    The dog slept on the cushion.
    The dromedary stood on the sand.
    The lion did whatever it pleased.
    The dromedary sat on the mat.


    Fixed strings to delete:
    The cat sat
    The dog slept
    The dromedary stood
    The lion
    The dromedary


    Finishing point
    on the mat.
    on the cushion.
    on the sand.
    did whatever it pleased.
    sat on the mat.


    I tried nesting it using.:

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A5,$A$22,""),A5,$A$23,""),A5,$A$24,""),A5,$A$25,""),$A$26,"")

    However, I guess this only works when there are MULTIPLE substitutions to be made from within a single cell. I have ONE substitution to make from each cell in the list, from a relatively small pool of possible strings.


    see attached sheet.

    I don't do VBA.... NO knowledge of it whatsoever!!
    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

  2. #2
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Need to delete selected stings from cell content

    Hello glen in C5 you can try
    =SUBSTITUTE($A5,$A24,"",1)
    then drag down.
    Here One specify the position of the string to be deleted by specifying 1 substitute will delete first occurrence only. If you specify two then it will replace second occurrence only and will not effect any other occurrence

    and if you use
    =SUBSTITUTE($A5,$A24,"") then it will replace all occurrences of the string supplied.
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    WANT TO SAY THANKS, HIT ADD REPUTATION (*) AT THE BOTTOM LEFT CORNER OF THE POST

    More we learn about excel, more it shows us, how less we know about it.

    for chemistry
    https://www.youtube.com/c/chemistrybyshivaansh

  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 2406
    Posts
    44,398

    Re: Need to delete selected stings from cell content

    Hi. It's red wine time... so I'll try this out in the morning.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,955

    Re: Need to delete selected stings from cell content

    Another way...
    =MID(A5,SEARCH("on",A5,1),99)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    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,398

    Re: Need to delete selected stings from cell content

    Neither of these worked.

    Ford's won't work for example 4 (the text to be retained doesn't necessarily begin with "on".

    Hemesh's will work, but only does so because i didn't randomise the order of the examples and list of text to be deleted.

    HOWEVER... if anyone is interested, this ghastly mess does work!! Brute force, perhaps...

    =IF(LEFT(A5,LEN(A24))=A24,REPLACE(A5,1,LEN(A24),""),IF(LEFT(A5,LEN(A25))=A24,REPLACE(A5,1,LEN(A25),"")*IF(LEFT(A5,LEN(A26))=A24,REPLACE(A5,1,LEN(A26),""),IF(LEFT(A5,LEN(A27))=A24,REPLACE(A5,1,LEN(A27),""),IF(LEFT(A5,LEN(A28))=A24,REPLACE(A5,1,LEN(A27),""),"")))))

    GHASTLY, but...

  6. #6
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Need to delete selected stings from cell content

    hello Glen,In that case try below array formula
    copy paste below in C5, Then Hold control and Shift together then Hit enter to make it array formula

    =SUBSTITUTE(A5,INDEX($A$24:$A$28,MAX(IF(LEFT(A5,LEN($A$24:$A$28))=$A$24:$A$28,ROW($A$24:$A$28)-23,0))),"")

    then drag down. Now you can randomise
    Attached Files Attached Files

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

    Re: Need to delete selected stings from cell content

    BRILLIANT.... Much more elegant than my monster. I had tried an array formula yesterday - but didn't get anywhere with it....

  8. #8
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Need to delete selected stings from cell content

    Glad I Could Help.

  9. #9
    Valued Forum Contributor Saarang84's Avatar
    Join Date
    02-19-2009
    Location
    Chennai, India
    MS-Off Ver
    XL 2003 to 2010
    Posts
    812

    Re: Need to delete selected stings from cell content

    I didn't know such a thing could be done in Excel.. Good question by Glenn and a brilliant solution by Hemesh.
    If my assistance has helped, there is a reputation icon * on the left hand corner below the post - you can show your appreciation to the user who has helped in resolving your requirement.

    If your requirement has been solved please mark your thread as Solved.
    In the menu bar above the very first post, select Thread Tools, then select "Mark this thread as Solved".

    Kindly use [FORMULA] or [CODE] tags when posting your code.

    Regards,
    Sarang

  10. #10
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Need to delete selected stings from cell content

    Thanks Saarang !

+ 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] If value is blank, delete content in selected cell
    By thelegazy in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-25-2013, 01:04 PM
  2. If value is blank, delete content in selected cell
    By thelegazy in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-25-2013, 11:52 AM
  3. IF same CONTENT FOUND IN CELL A THEN DELETE CONTENT IN B,C or D
    By mecutemecute in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-11-2013, 01:16 AM
  4. [SOLVED] delete cell content when other cell's content is removed
    By Pretpik in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-11-2012, 11:06 PM
  5. Replies: 2
    Last Post: 08-28-2011, 02:39 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