View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Parsing the directional out of addresses using nested IF .

On Thu, 23 Oct 2003 21:07:21 -0700, "dan"
wrote:

How would you go about parsing the last name out of a full
name string if there are variable information in the full
name string. i.e. some names will have Dr. or MS or two
middle names or a MR and MRS. I attempted a using a right
function but I could not find a function that would count
the characters from the Right to the left untill it found
a space. Does the search fuction have a left to right
switch?
Any Suggestions?


Dan,

Doublecheck the syntax on the stuff below, as I'm just giving you some general
notes and don't have enough time to rigorously test this morning.

If there are no suffixes in the string FullName, and the LastName is the last
word in the string, then LastName is the word following the LastSpace.

1. Compute number of spaces in the string:

NumSpace = LEN(FullName) - LEN(SUBSTITUTE(FullName," ",""))

2. Replace the LastSpace with some character (or string) that won't be in any
of the FullNames. I generally use a tilde (~).

FullNameWithTilde = SUBSTITUTE(FullName," ","~",NumSpace)

3. Get the location of the tilde within FullName:

LocTilde = FIND("~",FullNameWithTilde)

4. Use either a MID or RIGHT function to get the last word:

=MID(FullName,LocTilde+1,255)

or
=RIGHT(FullName,LEN(FullName)-LocTilde)

Obviously, all of the above can be nested, but I won't do it here because,
without debugging, I'd be certain to screw up the parentheses <g.

If the name might have suffixes, after you've parsed out the last word, you'd
need to check it against a list of possible suffixes, and proceed accordingly.

HTH,

--ron