使用Excel进行地址,string操作

我目前正在做一些有关数据看起来像这样的城市地址非常大的数据源的工作。

资源:

没有。 174史密斯街174号史密斯街174号174

我已经使用了一个函数来删除在extendoffice上显示的重复项。 https://www.extendoffice.com/documents/excel/2133-excel-remove-duplicate-characters-in-string.html

Function RemoveDupes2(txt As String, Optional delim As String = " ") As String Dim x With CreateObject("Scripting.Dictionary") .CompareMode = vbTextCompare For Each x In Split(txt, delim) If Trim(x) <> "" And Not .exists(Trim(x)) Then .Add Trim(x), Nothing Next If .Count > 0 Then RemoveDupes2 = Join(.keys, delim) End With 

结束function

第二列已成为这样:

没有。 174 / SMITH STREET TOR

我现在要做的是把它变成这个(删除编号并移动街道号码):

史密斯街174号5楼

最好的方法来完成这个? 有没有办法移动街道旁边的街道号码?

我的想法是将地址分解成不同的string,并将它们放入不同的列并重新排列它们。

另外我希望能用VBA编写一些东西,因为地址长短不一,间距也不一样

谢谢。

你可以试试这个:

 Function RemoveDupes2(txt As String, Optional delim As String = " ") As String Dim x As Variant, arr As Variant, temp As Variant With CreateObject("Scripting.Dictionary") .CompareMode = vbTextCompare For Each x In Split(txt, delim) If Trim(x) <> "" And Not .exists(Trim(x)) Then .Add Trim(x), Nothing Next If .count > 0 Then arr = Split(Replace(Join(.keys, delim), "NO." & delim, ""), delim) temp = arr(0) arr(0) = arr(1) arr(1) = temp RemoveDupes2 = Join(arr, delim) End If End With End Function