+ Reply to Thread
Results 1 to 7 of 7

Formula giving unexpected results

  1. #1
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    140

    Formula giving unexpected results

    Hey all,

    I have this formula:

    =TRIM(LEFT(MID(B2,FIND(". ",B2)+1,255),IF(ISNUMBER(SEARCH(",",B2)),FIND(",",MID(B2,FIND(". ",B2)+1,255))-1,RIGHT(FIND(" ",MID(B2,FIND(". ",B2)+1,255))-1))))

    When there is a comma after name:
    Lasalle Bank Na Plaintiff vs. Jonathan Jason Ferragut, et al Defendant

    I want to return Jonathan Jason Ferragut, for example.

    When there is no comma after the name:

    Hsbc Bank Usa Na Plaintiff vs. Faith M Hills Defendant

    I still want to return the name:
    Faith M Hills

    However, in the latter case, my formula is just returning a blank cell and not the name.

    I attached an example of the issue. Notice the last row, the field does not return the name, but rather a blank cell.

    Thanks for response.
    Attached Files Attached Files
    Last edited by johnmerlino; 11-30-2010 at 10:39 PM.

  2. #2
    Forum Contributor
    Join Date
    07-05-2006
    Location
    Canada
    MS-Off Ver
    2003, 2007
    Posts
    581

    Re: Formula giving unexpected results

    Hi,

    The portion of your formula that is causing you issues is the FALSE part of the inside IF statement. However, you will need to rearrange your statement somewhat. I'd recommend something like the following -- it is making the assumption that all of your data has the word " Defendant" in it. The thing you were trying to do with the space has the issue of matching any space, not just the one (last one) you were trying to match. (There are ways of doing it however.)

    The following may or may not meet your needs.

    PHP Code: 
    =TRIM(MID(A3,FIND("vs.",A3)+3,IF(ISERROR(FIND(",",MID(A3,FIND("vs.",A3)+3,LEN(A3)))),FIND(" Defendant",A3),FIND(",",A3))-(FIND("vs.",A3)+3))) 
    If the above is not suitable, my recommendation is to set up your statement as follows, Encapsulated in a TRIM(). You can fill in the commented sections with the appropriate formulas. Note: it's the last of the three lines I'm recommending as your setup, the first two just show how it's derived.

    PHP Code: 
    =MID(A3,[Find starting point],[Find length])
    =
    MID(A3,[Find starting point],[Find end point] - [Find starting point])
    =
    MID(A3,[Find starting point],IF([Comma exists], [Find comma point], [Find alternate split point]) - [Find starting point])

    [
    Find starting point] =(FIND("vs.",A3)+3)
    etc
    Please note, in the Formula ribbon, there is a button called Evaluate Formula. This button allows you to view what is being calculated at each step and see where your formula has issues. I find it very useful for diagnosing problems like this.

    Hope that helps,
    S

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Formula giving unexpected results

    The attached uses ttwo helper columns since I try to avoid long formulas:
    Attached Files Attached Files
    Ben Van Johnson

  4. #4
    Valued Forum Contributor SDruley's Avatar
    Join Date
    04-27-2009
    Location
    Conover, NC
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    415

    Re: Formula giving unexpected results

    My example may also help.
    Attached Files Attached Files
    Turn Data into Information
    Turn Information into Knowledge
    Turn Knowledge into Direction
    Turn Direction into Leadership
    Turn Leadership into Results
    Stephen Druley

    It's not how quickly you think
    But how deeply you think
    The quality of thinking is measured
    by remoteness to conformance
    Stephen Druley

  5. #5
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Formula giving unexpected results

    =TRIM(SUBSTITUTE(SUBSTITUTE(RIGHT(A1,LEN(A1)-FIND("vs.",A1&"vs.")-3),", et al",""),"Defendant",""))

    again simple! Works with all three examples, now the wait for the other cases!
    Regards
    Darren

    Update 12-Nov-2010 Still job hunting!

    If you are happy with the results, please add to our reputation by clicking the blue scales icon in the blue bar of the post.

    Learn something new each day, Embrace change do not fear it, evolve and do not become extinct!


  6. #6
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    140

    Re: Formula giving unexpected results

    Thanks for responses, especially last one. This ultimately worked:

    =TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(RIGHT(A1,LEN(A1)-FIND("vs.",A1&"vs.")-3),", et al",""),"Defendant",""),", Et Al","")," ""","")," Jr","")," Jr.",""))

  7. #7
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Formula giving unexpected results

    Jr. is redundant as you have already deleted Jr so Jr. will never appear! always substitute the shorter string last!

    So you either need to swap Jr and Jr. or just change Jr. to .

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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