Macro to move first name to last position in cell

  • Thread starter Thread starter Annette
  • Start date Start date
A

Annette

I need a macro that will transpose the first name with the last name in each
of the cells of numerous spreadsheets in column A ... some of the users had
put in the names first last while other formatted their as last, first ...

We want them to appear as last, first on all. Is there a method to do so?

Thanks!
 
one way:

Public Sub TransposeNames()
Dim rCell As Range
Dim sTemp As String
For Each rCell In Selection
sTemp = rCell.Text
If InStr(sTemp, ",") = 0 Then
sTemp = Application.Trim( _
Mid(sTemp, InStr(sTemp, " ")) & ", " & _
Left(sTemp, InStr(sTemp, " ") - 1))
rCell.Value = sTemp
End If
Next rCell
End Sub
 
Thanks!

JE McGimpsey said:
one way:

Public Sub TransposeNames()
Dim rCell As Range
Dim sTemp As String
For Each rCell In Selection
sTemp = rCell.Text
If InStr(sTemp, ",") = 0 Then
sTemp = Application.Trim( _
Mid(sTemp, InStr(sTemp, " ")) & ", " & _
Left(sTemp, InStr(sTemp, " ") - 1))
rCell.Value = sTemp
End If
Next rCell
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top