parsing full names in to 3 columns
Here's what I use . . .
Sub LastToFirst
On Error Resume Next
Dim cell as Range
Dim myRange as Variant
Dim lastCell as Variant
Dim LastFirstNames as Range
myRange = InputBox ("Enter the cell reference for hte first " & _
"cell in the column " & _
"containing the names you wish to convert. Example A1. The " & _
"names will be converted from Last First order to " & _
"First Last Order. ", "Name Conversion Software")
If myRange = "" Then
End
End If
Set myRange = Range(myRange)
myRange.Select
Set lastCell = Cells(16000, ActiveCell.Column).End(xlUp)
Set LastFirstNames = Range(Cells(2, ActiveCell.Column), lastCell)
LastFirstNames.Select
For Each cell in LastFirstNames
If Not IsEmpty(cell) Then _
ExtractValuea cell
Next
MsgBox "Names Have Succesfully Been Converted", vbOKOnly, "Name
Routine"
End Sub
Sub ExtractValue1(anyCell As Range)
Dim s As String
Dim N As Integer, i As Integer
Dim myLast As String
Dim myFirst As String
s = anyCell.Value
N = InStr(s, ",")
While N 0
i = i + 1
myLast = Left(s, N - 1)
s = Mid(s, N + 1)
anyCell.Value = s & Space(1) & myLast
SLen = Len(anyCell.Value)
anyCell.Value = Right(anyCell, SLen - 1)
N = InStr(s, ",")
Wend
i = i + 1
MsgBox "Names Have Succesfully Been Converted", vbOKOnly, "Name
Routine"
End Sub
You should be able to just copy this into a module and then run it and
it works great. However, now that I look back at this, it's kind of
clumsy and not commented. I wrote it along time ago and it works great
but I never got back to cleaning it up and putting in comments.
Here's some code to put names that are all in UPPER CASE into Proper
Case . . .
Sub ProperCaseNames
Dim PCName As Range
Dim PCNameRange As Variant
Dim lastPCName As Variant
Dim lastPCNameRange As Range
PCNameRange = InputBox("Enter the cell reference for the first " & _
"cell in the column " & _
"containing the names you wish to convert. Example A1. The " & _
"names will be converted from JOHN DOE to proper " & _
"case, John Doe. ", "Name Conversion Software")
If PCNameRange = "" Then
End
End If
Set PCNameRange = Range(PCNameRange)
PCNameRange.Select
Set lastPCName = Cells(65000, ActiveCell.Column).End(xlUp)
Set lastPCNameRange = Range(Cells(2, ActiveCell.Column), lastPCName)
lastPCNameRange.Select
For Each PCName In lastPCNameRange
IF PCName.HasFormula = False And Not IsEmpty(PCName) Then
PCName.Value = Application.Proper(PCName.Value)
End If
Next PCName
MsgBox "Names Have Succesfully Been Converted", vbOKOnly, "Name
Routine"
End Sub
I had to type all this code in because the PC where I have this stored
is not networked and so I couldn't just copy and past it in here.
Therefore, look out for any typos. I would just go ahead and past it
in and run it and of course, if there are any typos, then you'll get a
message. Please feel free to let me know if you have any problems with
any of this. I also have code that reverses the names back to Last to
First order.
|