【问题标题】:How to add a comma delimiter to the beginning of the city in an address如何在地址中的城市开头添加逗号分隔符
【发布时间】:2015-05-29 14:37:25
【问题描述】:

例子:

1412 Chestnut Street Philadelphia
494 W Germantown Pike Plymouth Meeting

我想在 200 个列表中的每个城市的开头添加一个逗号,但正如您在上面看到的,有时城市名称不会从单元格中的最后一个单词开始。

是否有可以在PhiladelphiaPlymouth Meeting 之前添加逗号的总体公式?

【问题讨论】:

  • 你的意思是,如何在 MS Excel 中做到这一点?
  • 并非没有更多信息。我不知道街道名称在哪里结束,而城市从494 W Germantown Pike Plymouth Meeting 开始。您的列表中是否有单独的城市列表?
  • 我希望它结束​​于 494 W Germantown Pike, Plymouth Meeting 或 494 W Germantown Pike, Plymouth Meeting;所以我可以使用文本来分栏并用逗号分隔(或除空格以外的任何分隔符)。
  • 示例:185 North West End Boulevard Quakertown //// 通常在最后一个单词中找到城市,但就像“普利茅斯会议”示例一样,它是最后两个单词

标签: excel cell delimiter comma city


【解决方案1】:

这是一个简单的示例,您可以根据自己的使用情况进行调整。假设我们在 A 列中有地址,在 B 列中有城市列表:

以下宏扫描地址以查找 [space][city] 并将城市替换为 [,][city]

Sub Commafication()
   Dim Acol As String, Ccol As String
   Dim ia As Long, ic As Long, va As String, vc As String

''''''''''''''''''''''''''''''''''''
'  update these as needed
Acol = "A"
Ccol = "B"
iamax = 3
icmax = 6
''''''''''''''''''''''''''''''''''''

   For ia = 1 To iamax
      va = Cells(ia, Acol).Text
      For ic = 1 To icmax
         vc = Cells(ic, Ccol).Text
         If InStr(va, " " & vc) > 0 Then
            Cells(ia, Acol).Value = Replace(va, vc, "," & vc)
         End If
      Next ic
   Next ia
End Sub

结果如下:

注意

这将按照您的要求在城市名称之前放置逗号,而不是在逗号和城市之间放置一个空格。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-01
    • 2021-05-31
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-22
    相关资源
    最近更新 更多