Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"snax500" wrote:
I want to use a macro to make the last name first even if there is a middle initial ( no space between comma and First name)... <snip I think I would be using InStr or some other string functions in Visual Basic. If you use the InStrRev function, you can find the location of the last space in the string. You would want to Trim() the string before you use InStrRev to avoid finding a trailing space. Select the first cell you want to convert, then run something like the following macro: Sub FormatNames() Dim LastSpace As Long Dim LastName As String Dim RestOfName As String Dim Name As String Name = Trim(ActiveCell.Value) While Name < "" LastSpace = InStrRev(Name, " ") LastName = Mid(Name, LastSpace + 1) RestOfName = Mid(Name, 1, LastSpace - 1) ActiveCell.Value = LastName & ", " & RestOfName ActiveCell.Offset(1, 0).Select Name = Trim(ActiveCell.Value) Wend End Sub --Shawn |