Function GetName(S As String, Ordinal As Long) As String
Dim X As Long, SplitPoint As Long
For X = 2 To Len(S)
If Mid(S, X, 1) = UCase(Mid(S, X, 1)) Then Exit For
Next
If Ordinal = 1 Then
GetName = Left(S, X - 1)
ElseIf Ordinal = 2 Then
GetName = Mid(S, X)
End If
End Function
Function PartName(s As String, Num As Long) As String
With CreateObject("VBScript.RegExp")
.Pattern = "(.+[a-z])([A-Z].+)"
PartName = Split(.Replace(s, "$1 $2"))(Num - 1)
End With
End Function
Excel Workbook | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | JohnSmith | John | Smith | ||
2 | Mary-AnnSmith | Mary-Ann | Smith | ||
3 | MaryFullerton-Smith | Mary | Fullerton-Smith | ||
4 | Mary-AnnFullerton-Smith | Mary-Ann | Fullerton-Smith | ||
Sheet1 |