J
Jim Berglund
Ron Rosenfeld kindly gave me the following:
Sub ParseAddr()
Dim myRegExp As Object, myMatches As Object
Dim rg As Range, c As Range
Dim i As Long
With ActiveSheet
Range("A:A").Select
Set rg = Selection
Set myRegExp = CreateObject("vbscript.regexp")
myRegExp.Pattern = "^(\D+)\s+(.*)\s(CALGARY|MELBOURNE|SYDNEY)" &
",?\s+([A-Z]{2})\s+(\w+)\s+(\(\d{3}\)\s+\d{3}-\d{4})"
For Each c In rg
If myRegExp.test(c.Text) = True Then
Set myMatches = myRegExp.Execute(c.Text)
For i = 0 To 5
c.Offset(0, i + 1) = myMatches(0).submatches(i)
Next i
End If
Next c
End With
End Sub
It works fine against the following data, creating 5 columns with the Name,
Address, City, Prov, and Telephone Number, respectively.
ABACO CHRISTIAN P 32 PATTERSON ME SW CALGARY, AB T3H2C7 (403) 238-2039
begin_of_the_skype_highlighting (403) 238-2039
end_of_the_skype_highlighting
'Just one tweak needed...
I'd like to separate the last name from the remainder of the name (which may
be anything from "P" to "DR QUINCY R & JULIE" and create 6 columns.
Would someone (preferable Ron), please explain to me how to do this?
Thanks, once again
Jim Berglund
Sub ParseAddr()
Dim myRegExp As Object, myMatches As Object
Dim rg As Range, c As Range
Dim i As Long
With ActiveSheet
Range("A:A").Select
Set rg = Selection
Set myRegExp = CreateObject("vbscript.regexp")
myRegExp.Pattern = "^(\D+)\s+(.*)\s(CALGARY|MELBOURNE|SYDNEY)" &
",?\s+([A-Z]{2})\s+(\w+)\s+(\(\d{3}\)\s+\d{3}-\d{4})"
For Each c In rg
If myRegExp.test(c.Text) = True Then
Set myMatches = myRegExp.Execute(c.Text)
For i = 0 To 5
c.Offset(0, i + 1) = myMatches(0).submatches(i)
Next i
End If
Next c
End With
End Sub
It works fine against the following data, creating 5 columns with the Name,
Address, City, Prov, and Telephone Number, respectively.
ABACO CHRISTIAN P 32 PATTERSON ME SW CALGARY, AB T3H2C7 (403) 238-2039
begin_of_the_skype_highlighting (403) 238-2039
end_of_the_skype_highlighting
'Just one tweak needed...
I'd like to separate the last name from the remainder of the name (which may
be anything from "P" to "DR QUINCY R & JULIE" and create 6 columns.
Would someone (preferable Ron), please explain to me how to do this?
Thanks, once again
Jim Berglund