View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen[_2_] Per Jessen[_2_] is offline
external usenet poster
 
Posts: 703
Default User Defined Functions to separate full names

On 21 Maj, 21:06, DZ wrote:
Hi

I want to create three user defined functions
1. FirstName
2. MiddleInitial
3. LastName

so that a user can use them by selecting the function(s) from the Paste
Function Dialog and then simply selecting a cell reference that contains the
full name.

I already know how to create the function arguments as follows

Function FirstName (FulNameCell as range)
Code----------------------
End Function

I need the complete code to get the first name etc

Also

Function Middleinitial (FulNameCell as range)
Code----------------------
End Function

Function LastName (FulNameCell as range)
Code----------------------
End Function

Thanks alot for help with this.

DZ


Hi

This should do it:

Function FirstName(FulNameCell As Range)
FullName = FulNameCell
For c = 1 To Len(FullName)
If Mid(FullName, c, 1) = " " Then
FnLen = c - 1
Exit For
End If
Next
FirstName = Left(FullName, FnLen)
End Function
Function LastName(FulNameCell As Range)
For c = Len(FulNameCell) To 1 Step -1
If Mid(FulNameCell, c, 1) = " " Then
FnLen = c
Exit For
End If
Next
LastName = Right(FulNameCell, Len(FulNameCell) - FnLen)

End Function


Function MiddleInitial(FulNameCell As Range)
For c = 1 To Len(FulNameCell)
If Mid(FulNameCell, c, 1) = " " Then
FnLen = c + 1
Exit For
End If
Next
For c = FnLen To Len(FulNameCell)
If Mid(FulNameCell, c, 1) = " " Then
FnMid = c - FnLen
Exit For
End If
Next
MiddleInitial = Mid(FulNameCell, FnLen, FnMid)
End Function

Regards,
Per