View Single Post
  #8   Report Post  
Bob Phillips
 
Posts: n/a
Default

Here is one way.

Enter this code in a standard code module

'---------------------------------------------------------------------
Private Function RESubString(Inp As String, _
Pattern As String, _
Optional N As Long = 0) As String
'---------------------------------------------------------------------
Dim oRegExp As Object, m As Object

On Error GoTo RE_error
Set oRegExp = CreateObject("VBScript.RegExp")
oRegExp.Pattern = Pattern
oRegExp.Global = True
Set m = oRegExp.Execute(Inp)
RESubString = IIf(m.Count 0, m(N).Value, "")
GoTo RE_Exit
RE_error:
RESubString = "RE Error"
RE_Exit:
Set oRegExp = Nothing
On Error GoTo 0
End Function

'---------------------------------------------------------------------
Public Function ConvertName(nme As String)
'---------------------------------------------------------------------
' Function: Extracts the last name from a names string, and the other
' first letters
'---------------------------------------------------------------------
Dim sRegExp As String
Dim arynames
Dim sLastName As String
Dim sFirtsNames As String
Dim sTemp As String
Dim i As Long

sRegExp =
"\b([a-z]+\s+)*[A-Z](\w+\S?)*([-'][A-Z](\w+\S?)*)?\b(?=(\s+([JS]r\.?|[IVX]+)
)?\s*$|,)"
sLastName = Replace(RESubString(nme, sREgExp), " ", "")
sFirstnames = Left(nme, Len(nme) - Len(sLastName))
arynames = Split(sFirstnames, " ")
For i = LBound(arynames) To UBound(arynames)
sTemp = sTemp & Left(arynames(i), 1)
Next i
ConvertName = LCase(sTemp & sLastName)
End Function


and then use in the worksheet like so

=ConvertName(A1)

--
HTH

Bob Phillips

"Shadowofthedarkgod" wrote in
message ...

I have this problem, see I want to create a script, I have the following
information available to me.

First name: John
MI: C
Last name: Doe

Now this is what I want; I want to convert this John C. Doe to "jcdoe".

Also
I have similar problems to with dual last names, like dela toya, I have to
convert from juan r. dela toya to jrdelatoya. How do I do that? Thanks!!