I am trying to cleaning up some addresses. I already have some code to change "Sw","Ne" and capitalizing them.
However, I would like to add one more step to tack on ordinals to rural addresses in the same code if possible.
all the addresses I need to updated start with 5 numbers then space then 3 numbers. "NNNNN NNN"
I have some code to add ordinals, I just need a way to only add it to those 3 numbers after the 5. Example "56579 123" to "56579 123rd" and leave the rest of the address alone.
Here is my current code.
Public Function TidyUp(sin As String) As String
Dim i As Long
arr = Split(sin, " ")
For i = LBound(arr) To UBound(arr)
If UCase(arr(i)) = "NE" Then arr(i) = "NE"
If UCase(arr(i)) = "NW" Then arr(i) = "NW"
If UCase(arr(i)) = "SE" Then arr(i) = "SE"
If UCase(arr(i)) = "SW" Then arr(i) = "SW"
Next i
TidyUp = Join(arr, " ")
End Function
Here is the ordinal function but this only works if i have a single number in a cell.
Function AddOrdinal(Address As String) As String
Select Case CLng(VBA.Right(Address, 1))
Case 1
AddOrdinal = Address & "st"
Case 2
AddOrdinal = Address & "nd"
Case 3
AddOrdinal = Address & "rd"
Case Else
AddOrdinal = Address & "th"
End Select
Select Case VBA.CLng(VBA.Right(Address, 2))
Case 11, 12, 13
AddOrdinal = Address & "th"
End Select
End Function
This is basically what I am looking to achieve.
Address List Expected Output
12345 673 Ave 12345 673rd Ave
213 N Apple St 213 N Apple St
69818 221st Rd 69818 221st Rd
569 Sw Maple Dr 569 SW Maple Dr
10005 654 Dr 10005 654th Dr
369 Ne Banana St 369 NE Banana St
54489 412th St 54489 412th St
986 W Timber St 986 W Timber St
79532 771 Dr 79532 771st Dr
126 E Washington Ave126 E Washington Ave
56898 422 Dr 56898 422nd Dr