Option Explicit
Dim NR As Long, Col As Long
Sub SortAddress()
'Jerry Beaucaire 5/4/2010
Dim cFind As Range, cFirst As Range
Dim AddrCol As Long
On Error Resume Next
'Add missing spaces
Set cFind = Cells.Find(What:=",", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If cFind Is Nothing Then Exit Sub
Set cFirst = cFind
Do
cFind.Offset(1, 0).Insert xlShiftDown
Set cFind = Cells.FindNext(After:=cFind)
Loop Until cFind.Address = cFirst.Address
'Setup table
NR = 2
Col = Cells(1, Columns.Count).End(xlToLeft).Column + 2
With Range(Cells(1, Col), Cells(1, Col + 4))
.Value = [{"First Name","Last Name","Address","City","Zip"}]
.Font.Bold = True
End With
'Split addresses with AREAS function
For AddrCol = 1 To Col - 2
ReformatData (AddrCol)
Next AddrCol
End Sub
Sub ReformatData(AddrCol As Long)
'Jerry Beaucaire 5/4/2010
'Reorganize groups of data into row format
Dim i As Long, RNG As Range
Set RNG = Columns(AddrCol).SpecialCells(xlCellTypeConstants)
For i = 1 To RNG.Areas.Count
Cells(NR, Col) = Left(RNG.Areas(i)(1), InStrRev(RNG.Areas(i)(1), " ") - 1)
Cells(NR, Col + 1) = Mid(RNG.Areas(i)(1), InStrRev(RNG.Areas(i)(1), " ") + 1)
Select Case RNG.Areas(i).Cells.Count
Case 3
Cells(NR, Col + 2) = RNG.Areas(i)(2)
Cells(NR, Col + 3) = Left(RNG.Areas(i)(3), InStr(RNG.Areas(i)(3), ",") - 1)
Cells(NR, Col + 4) = Mid(RNG.Areas(i)(3), InStrRev(RNG.Areas(i)(3), " ") + 1)
Case 4
Cells(NR, Col + 2) = RNG.Areas(i)(2) & " " & RNG.Areas(i)(3)
Cells(NR, Col + 3) = Left(RNG.Areas(i)(4), InStr(RNG.Areas(i)(4), ",") - 1)
Cells(NR, Col + 4) = Mid(RNG.Areas(i)(4), InStrRev(RNG.Areas(i)(4), " ") + 1)
End Select
NR = NR + 1
Next i
Set RNG = Nothing
End Sub
You can fix the one name that puts JR. alone as last name.
Bookmarks