View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Stefi Stefi is offline
external usenet poster
 
Posts: 2,646
Default Find last word in cell

This UDF returns the lastname (use space as Separchar):

Function Lastword(InputString As String, SeparChar As String) As String
Dim i As Long
Dim ByteStr, ResultStr As String
ResultStr = ""
For i = Len(InputString) To 1 Step -1
ByteStr = Mid(InputString, i, 1)
If ByteStr = SeparChar Then
ResultStr = Right(InputString, Len(InputString) - i)
Exit For
End If
Next i
Lastword = ResultStr
End Function

Regards,
Stefi


"Gordon Rainsford" wrote:

aph wrote:

Hi,

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

Any suggestiongs please.


Use the Mid & Left functions to separate the firstname from the
remainder, then do it again on the remainder to separate the initial
from the lastname.


--
Gordon Rainsford