+ Reply to Thread
Results 1 to 5 of 5

Retrieve first three words in a cell

  1. #1
    Registered User
    Join Date
    06-16-2011
    Location
    ohio
    MS-Off Ver
    Excel 2007
    Posts
    13

    Retrieve first three words in a cell

    I need to retrieve the first three words in a cell. Also, if there are less than three words in a cell I need it to retrieve the two or the one word still.

    Ex.
    A1 = This is a test
    A2 = Still a test
    A3 = Just test
    A4 = Test
    A5 = J P Morgan Chase

    I want it to return

    B1 = This is a
    B2 = Still a test
    B3 = Just test
    B4 = Test
    B5 = J P Morgan

    Please help me! I've been trying to use Trims and Left Substitutes but I haven't had any luck figuring it out. Every time I get something that gets me three words, it won't work for one or two words. Thank you so much in advance!

    Also, to save time so I'm not on here later asking about it. Is there one for the first two and four words with the same criteria as above?
    Last edited by Richww2; 06-30-2011 at 03:27 PM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Retrieve first three words in a cell

    PHP Code: 
    =if(iserror(search("#",substitute(a8," ","#",3))),a8,left(substitute(a8," ","#",3),search("#",substitute(a8," ";"#",3))-1)) 



  3. #3
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Retrieve first three words in a cell

    try this
    Please Login or Register  to view this content.
    copy into module and then use in your worksheet in any cell
    example:
    formula in cell B1: =splitit(A1)

    Best Regards

  4. #4
    Registered User
    Join Date
    06-16-2011
    Location
    ohio
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Retrieve first three words in a cell

    Thanks a ton both of you. They worked great! I can finally stop pulling my hair out.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Retrieve first three words in a cell

    or this UDF:

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    Last edited by snb; 06-16-2011 at 05:36 PM.

+ 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