GreenV27
asked on
Separating address number and street name from address1 field
Hi
I've been trying to find a program which splits a house number from a street name, I have ten of thousands to go through and the addresses are all in different forms. I have come across the below piece of code which seems to work marginally well. The only problem is that when it comes across an address like 1-3 COMMERCIAL ROAD, the excel cell automatically changes the 1-3 to 3-jan and I can't easily convert it back to 1-3. This even happens when I change the target column to a text format. Is there any way to get around this? Or alternatively is there any code out there that does the job better? I don't care if I do this in excel or access 2003.
Sub parseadd()
ActiveCell.Select
ActiveCell.Offset(0, 1).EntireColumn.Insert
ActiveCell.Offset(0, 2).EntireColumn.Insert
Do Until IsEmpty(ActiveCell) 'loop through rows
mylen = Len(ActiveCell)
bpos = mylen - 1
Do Until bpos = 0
If IsNumeric(Mid(ActiveCell, bpos, 1)) Then GoTo num:
bpos = bpos - 1
Loop
' No numbers place in onecell
onecell:
ActiveCell.Offset(0, 2).Select
ActiveCell.Value = Selection.Offset(0, -2)
GoTo reloop
num:
splitadd = InStr(bpos, ActiveCell, " ")
If splitadd = 0 Then GoTo onecell
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Mid(Selection.Offset(0, -1), (splitadd))
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Left(Selection.Offset(0, -2), (splitadd))
reloop:
ActiveCell.Offset(1, -2).Select
Loop
GoTo fini
fini:
End Sub
I've been trying to find a program which splits a house number from a street name, I have ten of thousands to go through and the addresses are all in different forms. I have come across the below piece of code which seems to work marginally well. The only problem is that when it comes across an address like 1-3 COMMERCIAL ROAD, the excel cell automatically changes the 1-3 to 3-jan and I can't easily convert it back to 1-3. This even happens when I change the target column to a text format. Is there any way to get around this? Or alternatively is there any code out there that does the job better? I don't care if I do this in excel or access 2003.
Sub parseadd()
ActiveCell.Select
ActiveCell.Offset(0, 1).EntireColumn.Insert
ActiveCell.Offset(0, 2).EntireColumn.Insert
Do Until IsEmpty(ActiveCell) 'loop through rows
mylen = Len(ActiveCell)
bpos = mylen - 1
Do Until bpos = 0
If IsNumeric(Mid(ActiveCell, bpos, 1)) Then GoTo num:
bpos = bpos - 1
Loop
' No numbers place in onecell
onecell:
ActiveCell.Offset(0, 2).Select
ActiveCell.Value = Selection.Offset(0, -2)
GoTo reloop
num:
splitadd = InStr(bpos, ActiveCell, " ")
If splitadd = 0 Then GoTo onecell
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Mid(Selection.Offset(0, -1), (splitadd))
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Left(Selection.Offset(0, -2), (splitadd))
reloop:
ActiveCell.Offset(1, -2).Select
Loop
GoTo fini
fini:
End Sub
Have you tried the ideas here
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another option is to put a ' character in front of any value.
Range("A4") = "'1-3"
Range("A4") = "'1-3"