+ Reply to Thread
Results 1 to 8 of 8

Extract word from text

  1. #1
    Forum Contributor
    Join Date
    06-11-2009
    Location
    Cape Town
    MS-Off Ver
    Microsoft 365
    Posts
    854

    Extract word from text

    I need to extract the second word in a column that contains text of different length? I have attached a sample file.
    Thanks in advance
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: Extract word from text

    Hi

    Try this formula:

    =TRIM(MID(A1,FIND(":",A1)+1,FIND(" -",A1)-4))
    Click *, if my suggestion helps you. Have a good day!!

  3. #3
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Extract word from text

    Quote Originally Posted by jraj1106 View Post
    =TRIM(MID(A1,FIND(":",A1)+1,FIND(" -",A1)-4))

    The 2nd part of that formula assumes that the ":" will always be the 3rd character. If you're going to make that assumption then why use the first FIND?

  4. #4
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Extract word from text

    i am going with the assumption that you may or may not have ":" and "-", but certainly will have " " on either side of the second word in the string. if ":" and "-" are constants, then you are better off using @jraj's formula.

    =MID(A1,FIND("|",SUBSTITUTE(A1," ","|",1)),FIND("|",SUBSTITUTE(A1," ","|",2))-FIND("|",SUBSTITUTE(A1," ","|",1)))

    EDIT:

    use the following monstrosity instead for best results.

    =MID(TRIM(A1),FIND("|",SUBSTITUTE(TRIM(A1)," ","|",1)),FIND("|",SUBSTITUTE(TRIM(A1)," ","|",2))-FIND("|",SUBSTITUTE(TRIM(A1)," ","|",1)))

    TRIM function reduces to 1 any number of contiguous white spaces greater than (or equal to) 1 within the string (not extremities - those are always zeroed out). in the earlier formula, if it encountered 2 contiguous white spaces, the result would be erroneous. due to TRIM, all such instances would be reduced to just a single instance. however, not all "white-space" induced errors, i will admit, can be countered with this strategy (as zbor has pointed out below).
    Last edited by icestationzbra; 05-09-2012 at 07:03 AM. Reason: enhancement due to TRIM
    - i.s.z -
    CSE, aka Array aka { }, formulae are confirmed with CONTROL+SHIFT+ENTER.
    Replace commas ( , ) with semicolons ( ; ) in formulae, if your locale setting demands.
    All good ideas are courtesy resources from this forum as well as others around the web.
    - e.o.m -

  5. #5
    Forum Contributor
    Join Date
    06-11-2009
    Location
    Cape Town
    MS-Off Ver
    Microsoft 365
    Posts
    854

    Re: Extract word from text

    Thanks to all for the solution.

  6. #6
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Extract word from text

    If you're always looking for the terms "Client" or "Customer" you could use:

    =INDEX({"Client","Customer"},MATCH(TRUE,INDEX(ISNUMBER(FIND({"Client","Customer"},A1)),0),0))

    But I'd probably go with icestationzbra's formula.

  7. #7
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: Extract word from text

    Or, to be more clear, those results work for different cases to extract word:

    jraj-> ABC DEF: word will return word
    icestationzbra -> ABC: word will return word
    icestationzbra -> ABC DEF: word will return DEF:
    jraj-> ABC DEF; word will return error
    icestationzbra -> ABC; word will return word
    icestationzbra -> ABC DEF; word will return DEF;

    Aland2929: what possible inputs you expect of above?

  8. #8
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Extract word from text

    see post #4 for updated formula.

+ 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