View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
K Dales[_2_] K Dales[_2_] is offline
external usenet poster
 
Posts: 1,163
Default Find last word in cell

Public Function FindName(ByVal MyName As String)

FindName = Right(MyName, Len(MyName) - InStrRev(MyName, " "))

End Function

Example of use:
MyName = "Kenneth Graham Dales"
LastName = FindName(MyName)
? LastName
Dales
MyName = Trim(Replace(MyName, LastName, ""))
? MyName
Kenneth Graham
MiddleName = FindName(MyName)
? MiddleName
Graham
FirstName = Trim(Replace(MyName, MiddleName, ""))
? FirstName
Kenneth

--
- K Dales


"aph" wrote:


Hi,

How can I find the last word in a cell containing "Firstname Initial
Lastname"? I have tried the Mid and Left functions with a for next loop
but I think I need to work backwards to find the space.

Any suggestiongs please.

Andrew


--
aph
------------------------------------------------------------------------
aph's Profile: http://www.excelforum.com/member.php...o&userid=17175
View this thread: http://www.excelforum.com/showthread...hreadid=476748