View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default reverse text based on a character

On Tue, 3 Feb 2009 08:45:00 -0800, george
wrote:

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