LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default User Defined Functions to separate full names

On Wed, 21 May 2008 12:06:00 -0700, 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


Here's something that might get you started:

======================================
Option Explicit
Function FirstName(FulNameCell As Range)
FirstName = ParseName(FulNameCell.Value, 0)
End Function
'------------------------------------
Function Middleinitial(FulNameCell As Range)
Middleinitial = ParseName(FulNameCell.Value, 2)
End Function
'------------------------------------
Function LastName(FulNameCell As Range)
LastName = ParseName(FulNameCell.Value, 3)
End Function
'----------------------------------------
Function ParseName(str As String, Part As Long) As String
'Part: 0 = First Name
' 1 = Middle Name
' 2 = Middle Initial
' 3 = Last Name
Dim re As Object, mc As Object, m As Object
Dim i As Long
Set re = CreateObject("vbscript.regexp")
re.Pattern = "^(\S+)\s?((\S?).*)\s(\S+)$"
If re.test(str) Then
Set mc = re.Execute(str)
ParseName = mc(0).submatches(Part)
End If
End Function
================================================== =
--ron


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Defined Functions [email protected] Excel Programming 1 May 25th 07 03:45 PM
How do i separate full names appearing in single cells? daveylee Excel Worksheet Functions 3 January 18th 06 09:51 PM
User Defined Functions - Help Text - Make it Easy for the User Andibevan[_2_] Excel Programming 4 March 17th 05 09:51 AM
user defined functions Alexander Bogomolny Excel Programming 4 July 25th 04 07:54 PM
excel functions and User defined functions Kanan Excel Programming 4 May 20th 04 11:21 PM


All times are GMT +1. The time now is 10:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"