reverse text based on a character

G

george

i want to change a cell that contains: First name, last name to read last
name, First name
 
K

Kevin B

The following formula will extract and concatenate the data for you:

=RIGHT(A1,LEN(A1)-FIND(",",A1,1)-1)&", "&LEFT(A1,(FIND(",",A1,1)-1))

Changing A1 to match the cell that contains the name.
 
R

Ron Rosenfeld

i want to change a cell that contains: First name, last name to read last
name, First name

You can do that with a macro:

<alt-F11> opens the VB Editor. Ensure your project is highlighted in the
Project Explorer window, then Insert/Module and paste the code below into the
window that opens.

To use this, select a range of cells; then <alt-F8> opens the macro dialog box.
Select the macro and <RUN>.

It will reverse the comma separated string.

======================================
Option Explicit
Sub RevNames()
Dim c As Range
Dim sTemp, sRes()
Dim temp
Dim i As Long
For Each c In Selection
If Len(c.Value) > 0 Then
sTemp = Split(c.Value, ",")
ReDim sRes(UBound(sTemp))
For i = UBound(sTemp) To 0 Step -1
sRes(UBound(sTemp) - i) = Trim(sTemp(i))
Next i
c.Value = Join(sRes, ", ")
End If
Next c
End Sub
==========================
--ron
 

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

Top