An easier way to get the last word from a string ?

S

Steve

Is there any way extract the last word from a string than this:

=IF(ISERR(FIND(" ",TRIM(A1),1)),TRIM(A1),RIGHT(TRIM(A1),MATCH("
",(MID(TRIM(A1),LEN(TRIM(A1))-ROW(INDIRECT("1:"&LEN(TRIM(A1))))+1,1)),0)-1))

Where A1 contains the string and the above needs to be entered as an array
input (Ctrl+Enter).

Also is there a simple non-VBA way of converting an array to a string, or
even a string reverse function ?

(I've tried the above in Excel 2K3,XP & 2K)


Regards


Steve
 
P

Peo Sjoblom

One way

=RIGHT(A1,LEN(A1)-SEARCH("^^",SUBSTITUTE(A1,"
","^^",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))

entered normally
 
S

Steve

Nice & Simple, thanks.




Peo Sjoblom said:
One way

=RIGHT(A1,LEN(A1)-SEARCH("^^",SUBSTITUTE(A1,"
","^^",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))

entered normally
 
B

Bernie Deitrick

Peo,

That formula would be improved by using TRIM - it returns nothing when there
is a trailing space:

=RIGHT(TRIM(A1),LEN(TRIM(A1))-SEARCH("^^",SUBSTITUTE(TRIM(A1),"
","^^",LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1)," ","")))))

HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top