+ Reply to Thread
Results 1 to 3 of 3

Truncate text strings using LEFT and FIND/SEARCH for multiple search terms

  1. #1
    Registered User
    Join Date
    04-16-2013
    Location
    Ireland
    MS-Off Ver
    Excel 2010
    Posts
    4

    Truncate text strings using LEFT and FIND/SEARCH for multiple search terms

    Hi,

    I have a column of data - containing text strings.
    The text strings are very similar (start and middle of strings are identical) but are unique due to characters at the end of each string.
    I would like to truncate the text strings - by finding the last "common" sub-string - which I specify - and use LEFT to return the remainder.

    The strings that I want to search for are
    1) "_reg_"
    2) "["
    3) "shiftflop"


    =IFERROR(LEFT(C2,FIND("_reg_",C2)-1),IFERROR(LEFT(C2,FIND("[",C2)-1),IFERROR(LEFT(C2,FIND("shiftflop",C2)-1),C2)))


    This works for the first 2 cases - but NOT the last.
    If I remove the first 2 and ONLY include the last it works fine!

    =IFERROR(LEFT(C2,FIND("shiftflop",C2)-1),C2)))

    Is there an error in the formula or a limitation when "nesting" like that ?
    Is there any issue including the char "["

    I also tried using search function:


    =IFERROR(LEFT(A1,SEARCH({"[","_reg_","shiftflop"},A1)-1),A1)

    I believe that SEARCH({"A","B","C"},A1)-1) is equivalent of
    search for any of the letters A,B OR C in cell A1 and return the cell position for the fist match you find.
    Is that correct?

    Again this worked for some cases but not all.

    I am not sure what the correct syntax is - so looking for some help.


    Thanks

  2. #2
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Truncate text strings using LEFT and FIND/SEARCH for multiple search terms

    The first formula works perfectly for me. I created text strings with all the examples that you gave (one per example) and the correct left string of characters was returned every time.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

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

    Re: Truncate text strings using LEFT and FIND/SEARCH for multiple search terms

    Hi and welcome to the forum

    Perhaps if you gave (or, preferable, uploaded) some samples to look at (some working, some not) we might be in a better position to offer help?
    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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