ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1325|回复: 0

对已实现的3级省市区地址匹配升级为5级匹配

[复制链接]

TA的精华主题

TA的得分主题

发表于 2018-8-9 12:22 | 显示全部楼层 |阅读模式
地址区县街道社区
北京市,市辖区,东城区,东华门街道办事处,银闸社区居委会北京市市辖区东城区东华门街道办事处银闸社区居委会
北京市,市辖区,西城区,景山街道办事处,东厂社区居委会北京市市辖区西城区景山街道办事处东厂社区居委会
北京市,市辖区,朝阳区,交道口街道办事处,智德社区居委会北京市市辖区朝阳区交道口街道办事处智德社区居委会
北京市,市辖区,丰台区,安定门街道办事处,南池子社区居委会北京市市辖区丰台区安定门街道办事处南池子社区居委会
北京市,市辖区,石景山区,北新桥街道办事处,黄图岗社区居委会已实现已实现已实现待实现待实现
北京市,市辖区,海淀区,东四街道办事处,灯市口社区居委会
北京市,市辖区,门头沟区,朝阳门街道办事处,正义路社区居委会
  1. Sub 提取省市() 'by KCFONG  学无止境,学懂说谢 2013-11-10
  2. Rows("482:65536").ClearContents
  3. If MsgBox("功能:根据本表A列县市区,在表“省市县代码对照表”中查找所在的省市县(区),并将结果返回到D列" & Chr(13) & Chr(13) & "重名的县区,不能正确进行匹配,手工修改再次提取会被覆盖,解决办法:将表“省市县代码对照表”中的重名县区所在行整行删除。" & Chr(13) & Chr(13) & "户名不规范的,可能不能进行匹配,返回为空,可手工输入,再次提取不会被覆盖。选【确定】立即匹配,选【取消】则放弃。", 1 + 64, "提示") = vbOK Then
  4. 't = Timer
  5. If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
  6. orng = Sheets("省市县代码对照表").[a1].CurrentRegion
  7.   With Sheets("省市县代码对照表")
  8.         .UsedRange.Replace What:="自治区", Replacement:="", LookAt:=xlPart
  9.        .UsedRange.Replace What:="新区", Replacement:="", LookAt:=xlPart
  10.         .UsedRange.Replace What:="省", Replacement:="", LookAt:=xlPart
  11.          .UsedRange.Replace What:="市", Replacement:="", LookAt:=xlPart
  12.           .UsedRange.Replace What:="地区", Replacement:="", LookAt:=xlPart
  13.            .UsedRange.Replace What:="盟", Replacement:="", LookAt:=xlPart
  14.             .UsedRange.Replace What:="县", Replacement:="", LookAt:=xlPart
  15.              .UsedRange.Replace What:="区", Replacement:="", LookAt:=xlPart
  16.   End With
  17. Rng = Sheets("省市县代码对照表").[a1].CurrentRegion
  18. Sheets("省市县代码对照表").[a1].CurrentRegion = orng

  19. Sheets("地址信息").Select
  20. Application.EnableEvents = False
  21. er = [a65536].End(xlUp).Row
  22. Range("c2:e65536").ClearContents
  23. rng1 = Range("a1:iv" & er)
  24. For r = 2 To UBound(rng1)
  25.     y = rng1(r, 1)
  26.     For rr = 2 To UBound(Rng)
  27.        If (y Like "*" & Rng(rr, 1) & "*" Or y Like "*" & Rng(rr, 4) & "*" And Rng(rr, 4) <> "") And (y Like "*" & Rng(rr, 2) & "*" Or y Like "*" & Rng(rr, 5) & "*" And Rng(rr, 5) <> "") And (y Like "*" & Rng(rr, 3) & "*" Or y Like "*" & Rng(rr, 6) & "*" And Rng(rr, 6) <> "") Then
  28.                 rng1(r, 3) = orng(rr, 1): rng1(r, 4) = orng(rr, 2): rng1(r, 5) = orng(rr, 3) '省级名称    地级市名称  县级名称
  29.                 GoTo line10:
  30.        'ElseIf (y Like "*" & Rng(rr, 2) & "*" Or (y Like "*" & Rng(rr, 5) & "*" And Rng(rr, 5) <> "")) And (y Like "*" & Rng(rr, 3) & "*" Or (y Like "*" & Rng(rr, 6) & "*" And Rng(rr, 6) <> "")) Then
  31.                 'rng1(r, 3) = oRng(rr, 1): rng1(r, 4) = oRng(rr, 2): rng1(r, 5) = oRng(rr, 3) '省级名称    地级市名称  县级名称
  32.        ElseIf (y Like "*" & Rng(rr, 1) & "*" Or y Like "*" & Rng(rr, 4) & "*" And Rng(rr, 4) <> "") And (y Like "*" & Rng(rr, 3) & "*" Or y Like "*" & Rng(rr, 6) & "*" And Rng(rr, 6) <> "") Then
  33.                 rng1(r, 3) = orng(rr, 1): rng1(r, 4) = orng(rr, 2): rng1(r, 5) = orng(rr, 3) '省级名称    地级市名称  县级名称
  34.        End If
  35.     Next rr
  36.    

  37. line10:
  38. Next r
  39. Range("a1:iv" & er) = rng1
  40. End If

  41. Application.EnableEvents = True
  42. End Sub



  43. Sub fsreset()

  44. Application.EnableEvents = True

  45. End Sub
复制代码
  1. Private Sub ComboBox1_Change()

  2. End Sub

  3. Private Sub ListBox1_Click()
  4. r = ActiveCell.Row
  5. W = Split(ListBox1, "|")

  6. Range("C" & r) = Trim(W(0))
  7. Range("d" & r) = Trim(W(1))
  8. Range("E" & r) = Trim(W(2))
  9. ListBox1.Visible = False
  10. End Sub

  11. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  12. If Target.Count <> 1 Then Exit Sub
  13. If Target.Column <> 1 Or Target.Row = 1 Then ListBox1.Visible = False: Exit Sub
  14. If Target = "" Then ListBox1.Visible = False: Exit Sub
  15. Application.EnableEvents = False
  16. ListBox1.Clear

  17. ListBox1.Top = Target.Top
  18. ListBox1.Left = Target.Left + Target.Width
  19. Rng = Sheets(1).[a1].CurrentRegion
  20. List = ""
  21. orng = Sheets("省市县代码对照表").[a1].CurrentRegion
  22.   With Sheets("省市县代码对照表")
  23.   '自治区
  24.    .UsedRange.Replace What:="自治区", Replacement:="", LookAt:=xlPart
  25.        .UsedRange.Replace What:="新区", Replacement:="", LookAt:=xlPart
  26.         .UsedRange.Replace What:="省", Replacement:="", LookAt:=xlPart
  27.          .UsedRange.Replace What:="市", Replacement:="", LookAt:=xlPart
  28.           .UsedRange.Replace What:="地区", Replacement:="", LookAt:=xlPart
  29.            .UsedRange.Replace What:="盟", Replacement:="", LookAt:=xlPart
  30.             .UsedRange.Replace What:="县", Replacement:="", LookAt:=xlPart
  31.              .UsedRange.Replace What:="区", Replacement:="", LookAt:=xlPart
  32.   End With
  33. Rng = Sheets("省市县代码对照表").[a1].CurrentRegion
  34. Sheets("省市县代码对照表").[a1].CurrentRegion = orng
  35.     y = Target.Text
  36.     For rr = 2 To UBound(Rng)
  37.        xx = orng(rr, 1) & "  |  " & orng(rr, 2) & "  |  " & orng(rr, 3)
  38.        If (y Like "*" & Rng(rr, 1) & "*" Or y Like "*" & Rng(rr, 4) & "*" And Rng(rr, 4) <> "") And (y Like "*" & Rng(rr, 2) & "*" Or y Like "*" & Rng(rr, 5) & "*" And Rng(rr, 5) <> "") And (y Like "*" & Rng(rr, 3) & "*" Or y Like "*" & Rng(rr, 6) & "*" And Rng(rr, 6) <> "") Then
  39.              If InStr(List, xx) = 0 Then ListBox1.AddItem xx:
  40.               List = List & xx & ","
  41.        End If
  42.     Next rr
  43.     For rr = 2 To UBound(Rng)
  44.        xx = orng(rr, 1) & "  |  " & orng(rr, 2) & "  |  " & orng(rr, 3)
  45.        If (y Like "*" & Rng(rr, 1) & "*" Or y Like "*" & Rng(rr, 4) & "*" And Rng(rr, 4) <> "") And (y Like "*" & Rng(rr, 3) & "*" Or y Like "*" & Rng(rr, 6) & "*" And Rng(rr, 6) <> "") Then
  46.               If InStr(List, xx) = 0 Then ListBox1.AddItem xx:
  47.                List = List & xx & ","
  48.        End If
  49.     Next rr
  50.     For rr = 2 To UBound(Rng)
  51.     xx = orng(rr, 1) & "  |  " & orng(rr, 2) & "  |  " & orng(rr, 3)
  52.        If (y Like "*" & Rng(rr, 1) & "*" Or y Like "*" & Rng(rr, 4) & "*" And Rng(rr, 4) <> "") And (y Like "*" & Rng(rr, 2) & "*" Or y Like "*" & Rng(rr, 5) & "*" And Rng(rr, 5) <> "") Then
  53.               If InStr(List, xx) = 0 Then ListBox1.AddItem xx:
  54.                List = List & xx & ","
  55.        End If
  56.     Next rr
  57. ListBox1.Visible = True
  58. If List = "" Then
  59.   MsgBox "Not found"
  60.   ListBox1.Visible = False
  61.   
  62.   End If

  63. Application.EnableEvents = True

  64. End Sub


复制代码


TIM截图20180809121521.jpg

匹配省市县区1次修改 v1.zip

162.29 KB, 下载次数: 59

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2025-1-11 20:45 , Processed in 0.017006 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表