Hello,
we extract information for street addresses, sometimes we receive house
number duplicated example:
123 123 Main Street
Does anyone know of a way to delete the first number so we just have the
correct address of 123 Main Street?
Thanks
Here is a macro that will remove the first word in a string IF it is repeated
at the second word.
I chose to not restrict the test to just numbers, thinking that sometimes
addresses include both numbers and letters: e.g. 123A 123A Fourth Avenue
To enter this Macro (Sub), <alt-F11> opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.
To use this Macro (Sub), first select the range you wish to process. Then
<alt-F8> opens the macro dialog box. Select the macro by name, and <RUN>.
======================================
Option Explicit
Sub DeDupAdr()
Dim c As Range
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "(\b\w+\b)\s+(?=\1)"
For Each c In Selection
c.Value = re.Replace(c.Value, "")
Next c
End Sub
======================================
--ron