need a macro to edit names in excel

  • Thread starter Thread starter Betsy
  • Start date Start date
B

Betsy

I'd like to create (or use someone else's) a macro to edit names in Excel
spreadsheets. I need a.) to remove the last name and comma from a
last-name-first listing, and b.) to remove the comma and first name from a
last-name-first listing. In a.) that would leave the cell with only the first
name remaining, and in b.) would leave only the last name remaining.

Anyone have any suggestions or available macro's?
thanks!
Betsy
 
Below are the two macros I have used to do this and not have any spaces that
the text to columns leaves (unless there's a way to do the text to column
that can take out the space that I don't know about). You'll have to change
the start range, but should do the trick. Hope this helps!

Option Explicit
Sub RemoveLastName()

Dim r As String
Dim listname As Range

Set listname = Range("A14")
Do Until listname = ""
Do
If Left(listname, 1) <> " " Then
listname = Right(listname, Len(listname) - 1)
Else:
listname = Right(listname, Len(listname) - 1)
Exit Do
End If
Loop
Set listname = listname.Offset(1, 0)
Loop

End Sub

Sub RemoveFirstName()

Dim r As String
Dim listname As Range

Set listname = Range("C14")
Do Until listname = ""
Do
If Right(listname, 1) <> "," Then
listname = Left(listname, Len(listname) - 1)
Else:
listname = Left(listname, Len(listname) - 1)
Exit Do
End If
Loop
Set listname = listname.Offset(1, 0)
Loop

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