Will,
One of the difficulties here is identifying what is a name and not fluff in
the name (Bob Phillips Jr. for instance, or Ian St John). Here is a regular
expressions utility that does all that, and a sub that calls it, and swaps
the names.
Sub NameSwap()
Dim sLast As String
Dim iPos As Long
With ActiveCell
sLast = LastName(.Value)
iPos = InStr(1, .Value, sLast)
.Value = sLast & ", " & Left(.Value, iPos - 1)
End With
End Sub
Function LastName(nme As String)
Const sRegExp = "\b([a-z]+ +)*(O'|Mc|Mac)?[A-Z]" & _
"(\w+\S?)*(-[A-Z](\w+\S?)*)?\b(?=(( +)" & _
"(Sr\.?|Snr\.?|Jr\.?|Jnr\.?|[IVX][IVX]*))|,|\s*$)"
Dim oRegExp As Object, oResult As Object
On Error GoTo RE_error
Set oRegExp = CreateObject("VBScript.RegExp")
oRegExp.Pattern = sRegExp
oRegExp.Global = True
Set oResult = oRegExp.Execute(nme)
LastName = IIf(oResult.Count > 0, oResult(0).Value, "")
GoTo RE_Exit
RE_error:
LastName = "RE Error"
RE_Exit:
Set oRegExp = Nothing
On Error GoTo 0
End Function
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)