LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Last Name First pt2

"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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"