Try this
Sub NameSwap()
Dim FinalRow As Integer
Dim NSLoop As Integer
Dim Zloop As Integer
Dim TmpEndString As String
Dim TmpStrtString As String
Dim NSstring As String
FinalRow = Worksheets("Sheet1").Range("A65536").End(xlUp).Row
For NSLoop = 1 To FinalRow
NSstring = Worksheets("Sheet1").Range("A" & NSLoop).Value
TmpEndString = ""
TmpStrtString = ""
For Zloop = Len(NSstring) To 1 Step -1
If Mid(NSstring, Zloop, 1) <> Chr$(32) Then
TmpEndString = Mid(NSstring, Zloop, 1) & TmpEndString
Else
TmpStrtString = Mid(NSstring, 1, Zloop)
NSstring = TmpStrtString & TmpEndString
Worksheets("Sheet2").Range("A" & NSLoop).Value = NSstring
Exit For
End If
Next Zloop
Next NSLoop
End Sub
You could use the array formula...
{=TRIM(RIGHT(A1,LEN(A1)-MAX((MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)=" ")*ROW(INDIRECT("1:"&LEN(A1)))))&", "&MID(A1,1,MAX((MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)=" ")*ROW(INDIRECT("1:"&LEN(A1))))))}
Note: Array formulas must be entered using the
Control+Shift+Enter key combination. The
outermost braces, {}, are not entered by you --
they're supplied by Excel in recognition of a
properly entered array formula.