#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,069
Default The last word

How do I extract the last word in a character string of words and spaces?

I appreciate your help, -John

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default The last word

With your name in A1 try

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

If this post helps click Yes
---------------
Jacob Skaria


"John" wrote:

How do I extract the last word in a character string of words and spaces?

I appreciate your help, -John

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,231
Default The last word

Jacob Skaria wrote...
With your name in A1 try

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

....

If the string were long with many spaces, this could fail.

If the string happens to end with trailing spaces, this WILL fail. The
work-around for that is another TRIM call.

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

A more robust approach is

=MID(TRIM(A1),FIND(CHAR(127),SUBSTITUTE(TRIM(A1)," ",CHAR(127),
LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))))+1,32767)

which assumes CHAR(127) wouldn't be found in the string. In the very
unlikely chance it could, the most robust approach involves using a
defined name like seq referring to the formula

=ROW(INDEX(Incurred!$1:$65536,1,1):INDEX(Incurred! $1:$65536,32767,1))

and using it in the formula

=MID(TRIM(A1),LOOKUP(2,1/(MID(" "&TRIM(A1),seq,1)=" "),seq),32767)
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default The last word

Thanks Harlan
--
If this post helps click Yes
---------------
Jacob Skaria


"Harlan Grove" wrote:

Jacob Skaria wrote...
With your name in A1 try

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

....

If the string were long with many spaces, this could fail.

If the string happens to end with trailing spaces, this WILL fail. The
work-around for that is another TRIM call.

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

A more robust approach is

=MID(TRIM(A1),FIND(CHAR(127),SUBSTITUTE(TRIM(A1)," ",CHAR(127),
LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))))+1,32767)

which assumes CHAR(127) wouldn't be found in the string. In the very
unlikely chance it could, the most robust approach involves using a
defined name like seq referring to the formula

=ROW(INDEX(Incurred!$1:$65536,1,1):INDEX(Incurred! $1:$65536,32767,1))

and using it in the formula

=MID(TRIM(A1),LOOKUP(2,1/(MID(" "&TRIM(A1),seq,1)=" "),seq),32767)

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default The last word

A more robust approach is

=MID(TRIM(A1),FIND(CHAR(127),SUBSTITUTE(TRIM(A1)," ",CHAR(127),
LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))))+1,32767)


Just out of curiosity... any special reason for choosing CHAR(127) as
opposed to using one of the rarely used sub-32 characters codes; for
example, CHAR(1)?

--
Rick (MVP - Excel)


"Harlan Grove" wrote in message
...
Jacob Skaria wrote...
With your name in A1 try

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

...

If the string were long with many spaces, this could fail.

If the string happens to end with trailing spaces, this WILL fail. The
work-around for that is another TRIM call.

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

A more robust approach is

=MID(TRIM(A1),FIND(CHAR(127),SUBSTITUTE(TRIM(A1)," ",CHAR(127),
LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))))+1,32767)

which assumes CHAR(127) wouldn't be found in the string. In the very
unlikely chance it could, the most robust approach involves using a
defined name like seq referring to the formula

=ROW(INDEX(Incurred!$1:$65536,1,1):INDEX(Incurred! $1:$65536,32767,1))

and using it in the formula

=MID(TRIM(A1),LOOKUP(2,1/(MID(" "&TRIM(A1),seq,1)=" "),seq),32767)




  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,231
Default The last word

"Rick Rothstein" wrote...
....
Just out of curiosity... any special reason for choosing CHAR(127) as
opposed to using one of the rarely used sub-32 characters codes; for
example, CHAR(1)?

....

Showing my age. Ever used paper tape as a storage medium?
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default The last word

LOL -- Yes... many, many years ago (but only for a short time before moving
on to IBM "punch cards").

--
Rick (MVP - Excel)


"Harlan Grove" wrote in message
...
"Rick Rothstein" wrote...
...
Just out of curiosity... any special reason for choosing CHAR(127) as
opposed to using one of the rarely used sub-32 characters codes; for
example, CHAR(1)?

...

Showing my age. Ever used paper tape as a storage medium?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 7, paste linked to word becomes black when word pdf'd Surffreak Excel Discussion (Misc queries) 0 June 1st 08 12:17 AM
Copy from Word to Excel, and retain indent, plus word wrap Eric Excel Discussion (Misc queries) 1 March 9th 07 03:15 AM
need formula to search column for a word and return another word Skyline Excel Discussion (Misc queries) 5 November 18th 05 10:00 PM
Print labels by using Excel data in a Word mail into word Zoey Excel Discussion (Misc queries) 1 November 1st 05 09:08 PM
Embedded word doc changed to image-need to change back to word. cflores Excel Discussion (Misc queries) 0 January 23rd 05 06:45 AM


All times are GMT +1. The time now is 05:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"