VBA Parsing Street Addresses

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,171
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have some street addresses in Column A. What I would like to do is to be able to parse the data into column C,D,E. Can someone plese help me!

Thanks in advance Stephen
Book1
ABCDE
11950 West Main St1950West MainSt
243 Allen Road43AllenRoad
343D Johnson Village B12-Apt 10143DJohnson VillageB12-Apt 101
4943 Thomas Ave943ThomasAve
511 Village Circle11VillageCircle
Sheet1
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Isolating the numeric portionof the street address is easy... all you need to do is:

Code:
=left(a1,find(" ",a1)-1)

But separating out the street name from the rest of it is non-trivial. the particular examples that you provided don't have any apparent consistancy in their basic structure. Is it really that important to separate the street name from the rest? You can get the non-numeric portion of the string by doing

Code:
=right(a1,len(a1)-len(b1)-1)

But to break that down further is going to be difficult.
 
Upvote 0
Try:

Code:
Sub Test()
    Dim WF As WorksheetFunction
    Dim Sh As Worksheet
    Dim Rng As Range
    Dim Cell As Range
    Dim Sp1 As Integer
    Dim Sp2 As Integer
    Set WF = WorksheetFunction
    Set Sh = Worksheets("Sheet1")
    Set Rng = Sh.Range("A1:A" & Sh.Range("A65536").End(xlUp).Row)
    For Each Cell In Rng
        Sp1 = InStr(1, Cell.Value, " ")
        If Len(Cell.Value) - Len(WF.Substitute(Cell.Value, " ", "")) > 2 Then
            Sp2 = InStr(1, WF.Substitute(Cell.Value, " ", "@", 3), "@")
        Else
            Sp2 = InStr(1, WF.Substitute(Cell.Value, " ", "@", 2), "@")
        End If
        Cell.Offset(0, 1).Value = Left(Cell.Value, Sp1 - 1)
        Cell.Offset(0, 2).Value = Mid(Cell.Value, Sp1 + 1, Sp2 - Sp1 - 1)
        Cell.Offset(0, 3).Value = Right(Cell.Value, Len(Cell.Value) - Sp2)
    Next Cell
End Sub
 
Upvote 0
I see that you already have some replies but I might as well join in the fun. HTH. Dave
Code:
Sub Parse()
'parses strings
'uses blank left to right to seperate address
Dim strtest As String, LastRow As Integer, cnt as Integer
Dim Temp As Integer, i As Integer, colcnt as Integer

LastRow = Sheets("sheet1").Cells(Sheets("sheet1") _
.Cells.Rows.Count, "A").End(xlUp).Row()

For cnt = 1 To LastRow
strtest = Sheets("sheet1").Cells(cnt, "A")

For colcnt = 3 To 4
For i = 1 To Len(strtest)
  Temp = Asc(Mid(strtest, i, 1))
  If Temp = 32 Then
  Sheets("sheet1").Cells(cnt, colcnt) = Left(strtest, i - 1)
  strtest = Right(strtest, Len(strtest) - i)
  Exit For
  End If
 Next i
Next colcnt

Sheets("sheet1").Cells(cnt, colcnt) = strtest
Next cnt
End Sub
edit: code change to correct dim statement
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,613
Members
449,238
Latest member
wcbyers

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top