If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Retrieving the last word in a field

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-12-04, 04:57
MichèleW MichèleW is offline
Registered User
 
Join Date: Nov 2003
Posts: 17
Retrieving the last word in a field

Is there a function that will retrieve the last 'word' typed in a field.
For example:

"My name is Anna" = "Anna"
"My father's age is 56" = "56"

The function 'rightwords' doesn't seem to exist in Access.

Thankyou for reading and eventually answering my question.
Reply With Quote
  #2 (permalink)  
Old 01-12-04, 09:36
mikezcg mikezcg is offline
Registered User
 
Join Date: Oct 2003
Posts: 311
try len() and instr() (not sure if im 100% correct these are from VB6 but should be something like this in exl

or some thing liek a loop backwards

S="Today is monday"
i=len(s)

for j = i to 1 step -1
if mid() exit for ' use mid here to see if the chr is a space
next j

ans=right(s,j)


Sorry didnt really have time to test this,,

u may also be able to split the string based on spaces into an array and then just return the last item in the array,,
i havent done that in xl either but in dot net so... im sure there is a way

M~
Reply With Quote
  #3 (permalink)  
Old 01-12-04, 11:59
shades shades is offline
Registered User
 
Join Date: Oct 2003
Posts: 1,091
If you are doing this in Excel (rather than Access), then try this formula.

=IF(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))=0,A1,RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1," ","*",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))))

[Edited to note that the target cell is A1, and you can put this formula into B1. Adjust as necessary.]
__________________
old, slow, and confused
but at least I'm inconsistent!

Rich
(retired Excel 2003 user, 3/28/2008)

How to ask a question on forums

Last edited by shades; 01-12-04 at 12:05.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On