Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Find last word in a string


Usually in a list of names, I frequently need to find the last word in a
field, i.e., locate the last space. Is there any way of doing this with
formulas alone or must I resort to VBA?


--
clearwaterdave
------------------------------------------------------------------------
clearwaterdave's Profile: http://www.excelforum.com/member.php...o&userid=19365
View this thread: http://www.excelforum.com/showthread...hreadid=565801

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Find last word in a string

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



clearwaterdave wrote:

Usually in a list of names, I frequently need to find the last word in a
field, i.e., locate the last space. Is there any way of doing this with
formulas alone or must I resort to VBA?

--
clearwaterdave
------------------------------------------------------------------------
clearwaterdave's Profile: http://www.excelforum.com/member.php...o&userid=19365
View this thread: http://www.excelforum.com/showthread...hreadid=565801


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Find last word in a string


Don Guillett Wrote:
=MID(TRIM(G5),FIND("·",SUBSTITUTE(TRIM(G5),"
","·",LEN(TRIM(G5))-LEN(SUBSTITUTE(G5," ",""))))+1,256)

--
Don Guillett
SalesAid Software

"clearwaterdave"
<clearwaterdave.2bmhvt_1154035508.7878@excelforu m-nospam.com wrote in
message
news:clearwaterdave.2bmhvt_1154035508.7878@excelfo rum-nospam.com...

Usually in a list of names, I frequently need to find the last word

in a
field, i.e., locate the last space. Is there any way of doing this

with
formulas alone or must I resort to VBA?


--
clearwaterdave

------------------------------------------------------------------------
clearwaterdave's Profile:
http://www.excelforum.com/member.php...o&userid=19365
View this thread:

http://www.excelforum.com/showthread...hreadid=565801



I have thoroughly digested this piece of art and understand how it
works -- ALMOST. Does anyone know the philosophy of how it works.
Using the string "Bill & Susan Vilbert", a 20 character string I have
tried to understand its workings. The second parm of the FIND field
seems to find the location of the last space but I don't understand
how. The first SUBSTITUTE assigns a "." to a location definded as the
string length minus the length of the string without any spaces. By my
calculations that would be 20 (string length) less 17 (string length
without spaces) giving 3. That would mean that the space located at
position 3 would be replaced by a period. In reality it is replacing
the space at position 13 with a peiod.

Since it is finding the right position and it is working, I have no
problem. It's just a slight mental block I have as to how it's finding
the 13th and not 3rd position.

What am I overlooking?

BY THE WAY Many, many thanks to all who helped me with this challenge.


--
clearwaterdave
------------------------------------------------------------------------
clearwaterdave's Profile: http://www.excelforum.com/member.php...o&userid=19365
View this thread: http://www.excelforum.com/showthread...hreadid=565801



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Find last word in a string

I like this formula (copied from Peo Sjoblom, IIRC) since the ^^ characters
don't usually appear in cells. Dots/periods appear much more often.

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

Len(a1)-LEN(SUBSTITUTE(A1," ",""))
Will tell you how many spaces are in A1.

Say a1 contains:
Bill & Susan Vilbert
=len(a1) returns 20
=LEN(SUBSTITUTE(A1," ",""))
returns 17
doing the subtraction returns 3.

So now the formula looks like:

=RIGHT(A1,LEN(A1)-FIND("^^",SUBSTITUTE(A1," ","^^",3)))

This portion:
SUBSTITUTE(A1," ", "^^",3)
returns:
"Bill & Susan^^Vilbert"
It replaced that 3rd (aka last) occurance with ^^.

The Find() will return 13 so the formula looks like:
=RIGHT(A1,LEN(A1)-13)

=======
Depending on the version of excel you're using, you can use:
Select the cell with the formula
tools|formula auditing|Evaluate formula
And step through each piece of the formula.
(IIRC, xl2002 added this.)

In earlier versions, you can highlight portions of the formula (in the formula
bar) and hit F9 to see how it evaluates.

Hit ctrl-z to revert
or edit|undo after you've changed it too much.

clearwaterdave wrote:

Don Guillett Wrote:
=MID(TRIM(G5),FIND("·",SUBSTITUTE(TRIM(G5),"
","·",LEN(TRIM(G5))-LEN(SUBSTITUTE(G5," ",""))))+1,256)

--
Don Guillett
SalesAid Software

"clearwaterdave"
<clearwaterdave.2bmhvt_1154035508.7878@excelforu m-nospam.com wrote in
message
news:clearwaterdave.2bmhvt_1154035508.7878@excelfo rum-nospam.com...

Usually in a list of names, I frequently need to find the last word

in a
field, i.e., locate the last space. Is there any way of doing this

with
formulas alone or must I resort to VBA?


--
clearwaterdave

------------------------------------------------------------------------
clearwaterdave's Profile:
http://www.excelforum.com/member.php...o&userid=19365
View this thread:

http://www.excelforum.com/showthread...hreadid=565801


I have thoroughly digested this piece of art and understand how it
works -- ALMOST. Does anyone know the philosophy of how it works.
Using the string "Bill & Susan Vilbert", a 20 character string I have
tried to understand its workings. The second parm of the FIND field
seems to find the location of the last space but I don't understand
how. The first SUBSTITUTE assigns a "." to a location definded as the
string length minus the length of the string without any spaces. By my
calculations that would be 20 (string length) less 17 (string length
without spaces) giving 3. That would mean that the space located at
position 3 would be replaced by a period. In reality it is replacing
the space at position 13 with a peiod.

Since it is finding the right position and it is working, I have no
problem. It's just a slight mental block I have as to how it's finding
the 13th and not 3rd position.

What am I overlooking?

BY THE WAY Many, many thanks to all who helped me with this challenge.

--
clearwaterdave
------------------------------------------------------------------------
clearwaterdave's Profile: http://www.excelforum.com/member.php...o&userid=19365
View this thread: http://www.excelforum.com/showthread...hreadid=565801


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,572
Default Find last word in a string

Taking nothing away from Peo, I do believe this was originated by Leo Heuser
around the turn of the century.

This sticks in memory because Leo's original formula used the @ to denote
the indeterminate character, and this caused a lot of false links to appear
in formulas.
--

Regards,

RD
----------------------------------------------------------------------------
-------------------
Please keep all correspondence within the Group, so all may benefit !
----------------------------------------------------------------------------
-------------------

"Dave Peterson" wrote in message
...
I like this formula (copied from Peo Sjoblom, IIRC) since the ^^ characters
don't usually appear in cells. Dots/periods appear much more often.

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

Len(a1)-LEN(SUBSTITUTE(A1," ",""))
Will tell you how many spaces are in A1.

Say a1 contains:
Bill & Susan Vilbert
=len(a1) returns 20
=LEN(SUBSTITUTE(A1," ",""))
returns 17
doing the subtraction returns 3.

So now the formula looks like:

=RIGHT(A1,LEN(A1)-FIND("^^",SUBSTITUTE(A1," ","^^",3)))

This portion:
SUBSTITUTE(A1," ", "^^",3)
returns:
"Bill & Susan^^Vilbert"
It replaced that 3rd (aka last) occurance with ^^.

The Find() will return 13 so the formula looks like:
=RIGHT(A1,LEN(A1)-13)

=======
Depending on the version of excel you're using, you can use:
Select the cell with the formula
tools|formula auditing|Evaluate formula
And step through each piece of the formula.
(IIRC, xl2002 added this.)

In earlier versions, you can highlight portions of the formula (in the
formula
bar) and hit F9 to see how it evaluates.

Hit ctrl-z to revert
or edit|undo after you've changed it too much.

clearwaterdave wrote:

Don Guillett Wrote:
=MID(TRIM(G5),FIND("·",SUBSTITUTE(TRIM(G5),"
","·",LEN(TRIM(G5))-LEN(SUBSTITUTE(G5," ",""))))+1,256)

--
Don Guillett
SalesAid Software

"clearwaterdave"
<clearwaterdave.2bmhvt_1154035508.7878@excelforu m-nospam.com wrote in
message
news:clearwaterdave.2bmhvt_1154035508.7878@excelfo rum-nospam.com...

Usually in a list of names, I frequently need to find the last word

in a
field, i.e., locate the last space. Is there any way of doing this

with
formulas alone or must I resort to VBA?


--
clearwaterdave

------------------------------------------------------------------------
clearwaterdave's Profile:
http://www.excelforum.com/member.php...o&userid=19365
View this thread:

http://www.excelforum.com/showthread...hreadid=565801


I have thoroughly digested this piece of art and understand how it
works -- ALMOST. Does anyone know the philosophy of how it works.
Using the string "Bill & Susan Vilbert", a 20 character string I have
tried to understand its workings. The second parm of the FIND field
seems to find the location of the last space but I don't understand
how. The first SUBSTITUTE assigns a "." to a location definded as the
string length minus the length of the string without any spaces. By my
calculations that would be 20 (string length) less 17 (string length
without spaces) giving 3. That would mean that the space located at
position 3 would be replaced by a period. In reality it is replacing
the space at position 13 with a peiod.

Since it is finding the right position and it is working, I have no
problem. It's just a slight mental block I have as to how it's finding
the 13th and not 3rd position.

What am I overlooking?

BY THE WAY Many, many thanks to all who helped me with this challenge.

--
clearwaterdave
------------------------------------------------------------------------
clearwaterdave's Profile:

http://www.excelforum.com/member.php...o&userid=19365
View this thread: http://www.excelforum.com/showthread...hreadid=565801


--

Dave Peterson


  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Find last word in a string

Could be....

I blame Peo for not reminding me <vbg.



RagDyeR wrote:

Taking nothing away from Peo, I do believe this was originated by Leo Heuser
around the turn of the century.

This sticks in memory because Leo's original formula used the @ to denote
the indeterminate character, and this caused a lot of false links to appear
in formulas.
--

Regards,

RD
----------------------------------------------------------------------------
-------------------
Please keep all correspondence within the Group, so all may benefit !
----------------------------------------------------------------------------
-------------------

"Dave Peterson" wrote in message
...
I like this formula (copied from Peo Sjoblom, IIRC) since the ^^ characters
don't usually appear in cells. Dots/periods appear much more often.

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

Len(a1)-LEN(SUBSTITUTE(A1," ",""))
Will tell you how many spaces are in A1.

Say a1 contains:
Bill & Susan Vilbert
=len(a1) returns 20
=LEN(SUBSTITUTE(A1," ",""))
returns 17
doing the subtraction returns 3.

So now the formula looks like:

=RIGHT(A1,LEN(A1)-FIND("^^",SUBSTITUTE(A1," ","^^",3)))

This portion:
SUBSTITUTE(A1," ", "^^",3)
returns:
"Bill & Susan^^Vilbert"
It replaced that 3rd (aka last) occurance with ^^.

The Find() will return 13 so the formula looks like:
=RIGHT(A1,LEN(A1)-13)

=======
Depending on the version of excel you're using, you can use:
Select the cell with the formula
tools|formula auditing|Evaluate formula
And step through each piece of the formula.
(IIRC, xl2002 added this.)

In earlier versions, you can highlight portions of the formula (in the
formula
bar) and hit F9 to see how it evaluates.

Hit ctrl-z to revert
or edit|undo after you've changed it too much.

clearwaterdave wrote:

Don Guillett Wrote:
=MID(TRIM(G5),FIND("·",SUBSTITUTE(TRIM(G5),"
","·",LEN(TRIM(G5))-LEN(SUBSTITUTE(G5," ",""))))+1,256)

--
Don Guillett
SalesAid Software

"clearwaterdave"
<clearwaterdave.2bmhvt_1154035508.7878@excelforu m-nospam.com wrote in
message
news:clearwaterdave.2bmhvt_1154035508.7878@excelfo rum-nospam.com...

Usually in a list of names, I frequently need to find the last word
in a
field, i.e., locate the last space. Is there any way of doing this
with
formulas alone or must I resort to VBA?


--
clearwaterdave

------------------------------------------------------------------------
clearwaterdave's Profile:
http://www.excelforum.com/member.php...o&userid=19365
View this thread:
http://www.excelforum.com/showthread...hreadid=565801


I have thoroughly digested this piece of art and understand how it
works -- ALMOST. Does anyone know the philosophy of how it works.
Using the string "Bill & Susan Vilbert", a 20 character string I have
tried to understand its workings. The second parm of the FIND field
seems to find the location of the last space but I don't understand
how. The first SUBSTITUTE assigns a "." to a location definded as the
string length minus the length of the string without any spaces. By my
calculations that would be 20 (string length) less 17 (string length
without spaces) giving 3. That would mean that the space located at
position 3 would be replaced by a period. In reality it is replacing
the space at position 13 with a peiod.

Since it is finding the right position and it is working, I have no
problem. It's just a slight mental block I have as to how it's finding
the 13th and not 3rd position.

What am I overlooking?

BY THE WAY Many, many thanks to all who helped me with this challenge.

--
clearwaterdave
------------------------------------------------------------------------
clearwaterdave's Profile:

http://www.excelforum.com/member.php...o&userid=19365
View this thread: http://www.excelforum.com/showthread...hreadid=565801


--

Dave Peterson


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,688
Default Find last word in a string

This array formula eliminates the need for "marker characters":

=MID(A1,MAX((MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1) =CHAR(32))*(ROW(INDIRECT("1:"&LEN(A1)))))+1,255)

My preference would be to use the "marker" method, though. It's not
volatile, isn't an array and is a few keystrokes shorter.

Biff

"RagDyeR" wrote in message
...
Taking nothing away from Peo, I do believe this was originated by Leo
Heuser
around the turn of the century.

This sticks in memory because Leo's original formula used the @ to denote
the indeterminate character, and this caused a lot of false links to
appear
in formulas.
--

Regards,

RD
----------------------------------------------------------------------------
-------------------
Please keep all correspondence within the Group, so all may benefit !
----------------------------------------------------------------------------
-------------------

"Dave Peterson" wrote in message
...
I like this formula (copied from Peo Sjoblom, IIRC) since the ^^
characters
don't usually appear in cells. Dots/periods appear much more often.

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

Len(a1)-LEN(SUBSTITUTE(A1," ",""))
Will tell you how many spaces are in A1.

Say a1 contains:
Bill & Susan Vilbert
=len(a1) returns 20
=LEN(SUBSTITUTE(A1," ",""))
returns 17
doing the subtraction returns 3.

So now the formula looks like:

=RIGHT(A1,LEN(A1)-FIND("^^",SUBSTITUTE(A1," ","^^",3)))

This portion:
SUBSTITUTE(A1," ", "^^",3)
returns:
"Bill & Susan^^Vilbert"
It replaced that 3rd (aka last) occurance with ^^.

The Find() will return 13 so the formula looks like:
=RIGHT(A1,LEN(A1)-13)

=======
Depending on the version of excel you're using, you can use:
Select the cell with the formula
tools|formula auditing|Evaluate formula
And step through each piece of the formula.
(IIRC, xl2002 added this.)

In earlier versions, you can highlight portions of the formula (in the
formula
bar) and hit F9 to see how it evaluates.

Hit ctrl-z to revert
or edit|undo after you've changed it too much.

clearwaterdave wrote:

Don Guillett Wrote:
=MID(TRIM(G5),FIND("·",SUBSTITUTE(TRIM(G5),"
","·",LEN(TRIM(G5))-LEN(SUBSTITUTE(G5," ",""))))+1,256)

--
Don Guillett
SalesAid Software

"clearwaterdave"
<clearwaterdave.2bmhvt_1154035508.7878@excelforu m-nospam.com wrote in
message
news:clearwaterdave.2bmhvt_1154035508.7878@excelfo rum-nospam.com...

Usually in a list of names, I frequently need to find the last word
in a
field, i.e., locate the last space. Is there any way of doing this
with
formulas alone or must I resort to VBA?


--
clearwaterdave

------------------------------------------------------------------------
clearwaterdave's Profile:
http://www.excelforum.com/member.php...o&userid=19365
View this thread:
http://www.excelforum.com/showthread...hreadid=565801


I have thoroughly digested this piece of art and understand how it
works -- ALMOST. Does anyone know the philosophy of how it works.
Using the string "Bill & Susan Vilbert", a 20 character string I have
tried to understand its workings. The second parm of the FIND field
seems to find the location of the last space but I don't understand
how. The first SUBSTITUTE assigns a "." to a location definded as the
string length minus the length of the string without any spaces. By my
calculations that would be 20 (string length) less 17 (string length
without spaces) giving 3. That would mean that the space located at
position 3 would be replaced by a period. In reality it is replacing
the space at position 13 with a peiod.

Since it is finding the right position and it is working, I have no
problem. It's just a slight mental block I have as to how it's finding
the 13th and not 3rd position.

What am I overlooking?

BY THE WAY Many, many thanks to all who helped me with this challenge.

--
clearwaterdave
------------------------------------------------------------------------
clearwaterdave's Profile:

http://www.excelforum.com/member.php...o&userid=19365
View this thread:
http://www.excelforum.com/showthread...hreadid=565801


--

Dave Peterson




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 -find records which DO NOT contain a particular text string JackBuff Excel Discussion (Misc queries) 5 May 23rd 06 05:40 PM
Word could not parse your query options into a valid sql string Lizzzzzzzz Excel Discussion (Misc queries) 4 April 24th 06 12:08 PM
Find 2nd instance of a word in a range. Grumpy Grandpa Excel Worksheet Functions 8 December 5th 05 03:29 PM
How can I use find and replace to delete a word in Excel? callpaultwt Excel Discussion (Misc queries) 2 December 1st 05 09:11 PM
How to find if a string starts with a digit galsaba Excel Worksheet Functions 1 March 4th 05 06:01 PM


All times are GMT +1. The time now is 01:44 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"