PC Review


Reply
Thread Tools Rate Thread

How can I isolate the last two words in a text string?

 
 
Steve Gibbs
Guest
Posts: n/a
 
      23rd Nov 2008
I have found a formula that works great for retrieving the last word from a
string of charactors in a cell.
If the string in Cell A1 is: "How do I return the last two words?", the
formula below will give me the last word. (Isn't it nice sometimes to have
the last word?)

{=RIGHT(A1,MATCH(" ",MID(A1,LEN(A1)-ROW(INDIRECT("1:"&LEN(A1))),1),0))}
This will return "words?".

How can I modify this or, what other formula will return, "two words?".

I think this is a very slick formula, but I don't quite understand it well
enough to figure out how to modify the match to find the second blank.

Note: I found this formula in Osborne, THE COMPLETE REFERENCE EXCEL 2000 by
Kathy Ivens and Conrad Carlberg.
 
Reply With Quote
 
 
 
 
JE McGimpsey
Guest
Posts: n/a
 
      23rd Nov 2008
Assuming at least three words, one way:

=MID(A1, FIND("^", SUBSTITUTE(A1," ","^",LEN(A1) -
LEN(SUBSTITUTE(A1," ", "")) - 1)) + 1, 255)

In article <D91E3361-FE55-4E60-B2ED-(E-Mail Removed)>,
Steve Gibbs <Steve (E-Mail Removed)> wrote:

> I have found a formula that works great for retrieving the last word from a
> string of charactors in a cell.
> If the string in Cell A1 is: "How do I return the last two words?", the
> formula below will give me the last word. (Isn't it nice sometimes to have
> the last word?)
>
> {=RIGHT(A1,MATCH(" ",MID(A1,LEN(A1)-ROW(INDIRECT("1:"&LEN(A1))),1),0))}
> This will return "words?".
>
> How can I modify this or, what other formula will return, "two words?".
>
> I think this is a very slick formula, but I don't quite understand it well
> enough to figure out how to modify the match to find the second blank.
>
> Note: I found this formula in Osborne, THE COMPLETE REFERENCE EXCEL 2000 by
> Kathy Ivens and Conrad Carlberg.

 
Reply With Quote
 
Niek Otten
Guest
Posts: n/a
 
      23rd Nov 2008
=RIGHT(A1,LEN(A1)-FIND("\",SUBSTITUTE(A1," ","\",LEN(A1)-LEN(SUBSTITUTE(A1,"
",))-1)))

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"Steve Gibbs" <Steve (E-Mail Removed)> wrote in message
news91E3361-FE55-4E60-B2ED-(E-Mail Removed)...
>I have found a formula that works great for retrieving the last word from a
> string of charactors in a cell.
> If the string in Cell A1 is: "How do I return the last two words?", the
> formula below will give me the last word. (Isn't it nice sometimes to
> have
> the last word?)
>
> {=RIGHT(A1,MATCH(" ",MID(A1,LEN(A1)-ROW(INDIRECT("1:"&LEN(A1))),1),0))}
> This will return "words?".
>
> How can I modify this or, what other formula will return, "two words?".
>
> I think this is a very slick formula, but I don't quite understand it well
> enough to figure out how to modify the match to find the second blank.
>
> Note: I found this formula in Osborne, THE COMPLETE REFERENCE EXCEL 2000
> by
> Kathy Ivens and Conrad Carlberg.


 
Reply With Quote
 
Steve Gibbs
Guest
Posts: n/a
 
      24th Nov 2008
Thank you Niek, Your solution works great!
JE, I got an error message that there were too many arguments. I double and
triple checked my typing. Your solution is different than Niek's. I would
like to see yours work. Please check the solution. If it is right, then I
will try it again. Thanks.

"Steve Gibbs" wrote:

> I have found a formula that works great for retrieving the last word from a
> string of charactors in a cell.
> If the string in Cell A1 is: "How do I return the last two words?", the
> formula below will give me the last word. (Isn't it nice sometimes to have
> the last word?)
>
> {=RIGHT(A1,MATCH(" ",MID(A1,LEN(A1)-ROW(INDIRECT("1:"&LEN(A1))),1),0))}
> This will return "words?".
>
> How can I modify this or, what other formula will return, "two words?".
>
> I think this is a very slick formula, but I don't quite understand it well
> enough to figure out how to modify the match to find the second blank.
>
> Note: I found this formula in Osborne, THE COMPLETE REFERENCE EXCEL 2000 by
> Kathy Ivens and Conrad Carlberg.

 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      24th Nov 2008
Quadruple check it (or paste from the message). It works.

In article <23E7D6E4-3920-401B-8887-(E-Mail Removed)>,
Steve Gibbs <(E-Mail Removed)> wrote:

> JE, I got an error message that there were too many arguments. I double and
> triple checked my typing.

 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      24th Nov 2008
On Sun, 23 Nov 2008 14:29:01 -0800, Steve Gibbs <Steve
(E-Mail Removed)> wrote:

>I have found a formula that works great for retrieving the last word from a
>string of charactors in a cell.
>If the string in Cell A1 is: "How do I return the last two words?", the
>formula below will give me the last word. (Isn't it nice sometimes to have
>the last word?)
>
>{=RIGHT(A1,MATCH(" ",MID(A1,LEN(A1)-ROW(INDIRECT("1:"&LEN(A1))),1),0))}
>This will return "words?".
>
>How can I modify this or, what other formula will return, "two words?".
>
>I think this is a very slick formula, but I don't quite understand it well
>enough to figure out how to modify the match to find the second blank.
>
>Note: I found this formula in Osborne, THE COMPLETE REFERENCE EXCEL 2000 by
>Kathy Ivens and Conrad Carlberg.


So long as your words are some reasonable length, something like:

=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),198))

will return the last two words.
--ron
 
Reply With Quote
 
Steve Gibbs
Guest
Posts: n/a
 
      28th Nov 2008
I recieved four different solutions to my problem. All four work. This
solution is the shortest, least complicated and works the best. Testing the
solution with different strings consisting of one word, two word, three word,
and longer sentances, this is the only solution that would return a single
word in an one word sentance. If a blind space exists at the end of a word
only Niek Otten's solution would return the last two words. If there are two
blind spaces ant the end of the sentance none of the solutions return any
words. For my purpose Ron Rosenfeld's solution was best. Thanks.

"Ron Rosenfeld" wrote:

> On Sun, 23 Nov 2008 14:29:01 -0800, Steve Gibbs <Steve
> (E-Mail Removed)> wrote:
>
> >I have found a formula that works great for retrieving the last word from a
> >string of charactors in a cell.
> >If the string in Cell A1 is: "How do I return the last two words?", the
> >formula below will give me the last word. (Isn't it nice sometimes to have
> >the last word?)
> >
> >{=RIGHT(A1,MATCH(" ",MID(A1,LEN(A1)-ROW(INDIRECT("1:"&LEN(A1))),1),0))}
> >This will return "words?".
> >
> >How can I modify this or, what other formula will return, "two words?".
> >
> >I think this is a very slick formula, but I don't quite understand it well
> >enough to figure out how to modify the match to find the second blank.
> >
> >Note: I found this formula in Osborne, THE COMPLETE REFERENCE EXCEL 2000 by
> >Kathy Ivens and Conrad Carlberg.

>
> So long as your words are some reasonable length, something like:
>
> =TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),198))
>
> will return the last two words.
> --ron
>

 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      28th Nov 2008
On Fri, 28 Nov 2008 09:14:00 -0800, Steve Gibbs
<(E-Mail Removed)> wrote:

>I recieved four different solutions to my problem. All four work. This
>solution is the shortest, least complicated and works the best. Testing the
>solution with different strings consisting of one word, two word, three word,
>and longer sentances, this is the only solution that would return a single
>word in an one word sentance. If a blind space exists at the end of a word
>only Niek Otten's solution would return the last two words. If there are two
>blind spaces ant the end of the sentance none of the solutions return any
>words. For my purpose Ron Rosenfeld's solution was best. Thanks.


Thanks for the feedback.

Please make this small change in my contribution -- it will get rid of the
trailing spaces problem and should have been there originally:

=TRIM(RIGHT(SUBSTITUTE(TRIM(A1)," ",REPT(" ",99)),198))

--ron
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
isolate text within a string? Rich P Microsoft C# .NET 4 15th Sep 2009 08:34 PM
isolate date from a text string into another cell Tacrier Microsoft Excel Misc 5 11th Oct 2008 12:00 AM
Searching for Key Words in a String of Text =?Utf-8?B?QW5kcmV3?= Microsoft Access Queries 10 11th Apr 2006 04:56 PM
Separating Words From a Text String =?Utf-8?B?dnF0aG9tZg==?= Microsoft Excel Programming 1 18th Aug 2005 12:31 PM
isolate number from string of text Stephen R Microsoft Excel Discussion 8 4th Aug 2005 08:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:52 PM.