Hi, how can below codes can be modified to clean the addresses? Suburb name and State names have unwanted spaces and messy.
WorksheetDummy.xlsm | ||||
---|---|---|---|---|
A | B | |||
1 | Raw Address | Cleaned Address | ||
2 | 1 Co Street WALLA WAL LA NS W | 1 Co Street WALLA WALLA NSW | ||
3 | Lock Cres MILB AC T | Lock Cres MILB ACT | ||
4 | cnr March St/June Sts HENTY N SW | cnr March St/June Sts HENTY NSW | ||
5 | 4 Apra Street ALBURYQ LD | 4 apra Street ALBURY QLD | ||
6 | Cnr Bu St & Ur Road LA VINGTON N T | Cnr Bu St & Ur Road LAVINGTON NT | ||
7 | May Road LAVINGTON NSW | May Road LAVINGTON NSW | ||
8 | 1 Octo Street JIND ERA W A | 1 OctoStreet JINDERA WA | ||
9 | 4 Nov Road JINDERA S A | 4 NovRoad JINDERA SA | ||
10 | 7 April Court BURRUM CK T AS | 7 April Court BURRUMCK TAS | ||
Sheet3 |
VBA Code:
Function TidySpaces(s As String) As String
Dim RX As Object
Dim Pat As Variant
Const Patterns As String = "([a-z])( )([a-z])#(\d)( )(\d)#(\/)( )(.)#([A-Z])( )([A-Z])#([A-Z])( )([a-z])"
Set RX = CreateObject("VBScript.RegExp")
RX.Global = True
For Each Pat In Split(Patterns, "#")
RX.Pattern = Pat
s = RX.Replace(s, "$1$3")
Next Pat
TidySpaces = s
End Function