LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,069
Default Splitting up address

I have a need of splitting up an address from a field to seperate the numbers
from the street name.

I found this Regex example posted by Ron Rosenfeld that does some of the job

######################
To use it, enter a formula of the type:

=parseaddr(cell_ref,Index)

where cell_ref contains your original string and Index is a number from 1 to 3
indicating which section of the address you wish to pull out (see the comment
in the UDF).

To enter the UDF, <alt-F11 opens the VBEditor. Ensure your project is
highlighted in the project explorer window, then Insert Module and paste the
code below into the window that opens:

=========================================
Option Explicit
Function ParseAddr(str As String, Index As Long) As String

'Index: 1 = part before street number
' 2 = street number with optional letter
' 3 = part after street number

Dim re As Object
Dim mc As Object
Set re = CreateObject("vbscript.regexp")
re.IgnoreCase = True
re.Global = True
re.Pattern = "^((\D+)(\s))?((\d+[A-Z]?)(\s))(.*$)"
If re.test(str) = True Then
Set mc = re.Execute(str)
Select Case Index
Case Is = 1
ParseAddr = mc(0).submatches(1)
Case Is = 2
ParseAddr = mc(0).submatches(4)
Case Is = 3
ParseAddr = mc(0).submatches(6)
Case Else
ParseAddr = ""
End Select
End If
End Function
==============================================
###############

The above works great for addresses formated like

23 Some Street
23a Some Street

But I have things like:

2/3 Some Street
2/3-4 Some Street
Unit 2, 3 Some Street
Unit 2/3 Some Street

I did some reading on Regex but I'm not sure how I can expand on Ron's
original post to also take into account the other formats.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Splitting Address Info - Text to Columns betany70 Excel Discussion (Misc queries) 4 October 12th 07 09:54 PM
How do I avoid excel change absolute address to relative address Miguel Excel Discussion (Misc queries) 3 May 10th 07 11:18 PM
Splitting Numeric data from Text (Street Address Help) Cameron Excel Discussion (Misc queries) 2 December 5th 06 10:18 PM
Splitting comma separated lines of an address for mail merge. Chuda Excel Discussion (Misc queries) 1 September 12th 06 01:04 PM
How do I import Office address book to Outlook Express address bo. snnorp Excel Discussion (Misc queries) 2 February 22nd 05 11:47 AM


All times are GMT +1. The time now is 04:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"