View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
aph aph is offline
external usenet poster
 
Posts: 1
Default Find last word in cell


Kenneth

Works perfectly - thanks (I am sure the others do as well but I do like
a 1 line !)

Andrew


K Dales Wrote:
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




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