|
地址 | | 省 | 市 | 区县 | 街道 | 社区 | 北京市,市辖区,东城区,东华门街道办事处,银闸社区居委会 | | 北京市 | 市辖区 | 东城区 | 东华门街道办事处 | 银闸社区居委会 | 北京市,市辖区,西城区,景山街道办事处,东厂社区居委会 | | 北京市 | 市辖区 | 西城区 | 景山街道办事处 | 东厂社区居委会 | 北京市,市辖区,朝阳区,交道口街道办事处,智德社区居委会 | | 北京市 | 市辖区 | 朝阳区 | 交道口街道办事处 | 智德社区居委会 | 北京市,市辖区,丰台区,安定门街道办事处,南池子社区居委会 | | 北京市 | 市辖区 | 丰台区 | 安定门街道办事处 | 南池子社区居委会 | 北京市,市辖区,石景山区,北新桥街道办事处,黄图岗社区居委会 | | 已实现 | 已实现 | 已实现 | 待实现 | 待实现 | 北京市,市辖区,海淀区,东四街道办事处,灯市口社区居委会 | | | | | | | 北京市,市辖区,门头沟区,朝阳门街道办事处,正义路社区居委会 | | | | | | |
- Sub 提取省市() 'by KCFONG 学无止境,学懂说谢 2013-11-10
- Rows("482:65536").ClearContents
- If MsgBox("功能:根据本表A列县市区,在表“省市县代码对照表”中查找所在的省市县(区),并将结果返回到D列" & Chr(13) & Chr(13) & "重名的县区,不能正确进行匹配,手工修改再次提取会被覆盖,解决办法:将表“省市县代码对照表”中的重名县区所在行整行删除。" & Chr(13) & Chr(13) & "户名不规范的,可能不能进行匹配,返回为空,可手工输入,再次提取不会被覆盖。选【确定】立即匹配,选【取消】则放弃。", 1 + 64, "提示") = vbOK Then
- 't = Timer
- If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
- orng = Sheets("省市县代码对照表").[a1].CurrentRegion
- With Sheets("省市县代码对照表")
- .UsedRange.Replace What:="自治区", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="新区", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="省", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="市", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="地区", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="盟", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="县", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="区", Replacement:="", LookAt:=xlPart
- End With
- Rng = Sheets("省市县代码对照表").[a1].CurrentRegion
- Sheets("省市县代码对照表").[a1].CurrentRegion = orng
-
- Sheets("地址信息").Select
- Application.EnableEvents = False
- er = [a65536].End(xlUp).Row
- Range("c2:e65536").ClearContents
- rng1 = Range("a1:iv" & er)
- For r = 2 To UBound(rng1)
- y = rng1(r, 1)
- For rr = 2 To UBound(Rng)
- 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
- rng1(r, 3) = orng(rr, 1): rng1(r, 4) = orng(rr, 2): rng1(r, 5) = orng(rr, 3) '省级名称 地级市名称 县级名称
- GoTo line10:
- '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
- 'rng1(r, 3) = oRng(rr, 1): rng1(r, 4) = oRng(rr, 2): rng1(r, 5) = oRng(rr, 3) '省级名称 地级市名称 县级名称
- 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
- rng1(r, 3) = orng(rr, 1): rng1(r, 4) = orng(rr, 2): rng1(r, 5) = orng(rr, 3) '省级名称 地级市名称 县级名称
- End If
- Next rr
-
- line10:
- Next r
- Range("a1:iv" & er) = rng1
- End If
- Application.EnableEvents = True
- End Sub
- Sub fsreset()
- Application.EnableEvents = True
- End Sub
复制代码- Private Sub ComboBox1_Change()
- End Sub
- Private Sub ListBox1_Click()
- r = ActiveCell.Row
- W = Split(ListBox1, "|")
- Range("C" & r) = Trim(W(0))
- Range("d" & r) = Trim(W(1))
- Range("E" & r) = Trim(W(2))
- ListBox1.Visible = False
- End Sub
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Count <> 1 Then Exit Sub
- If Target.Column <> 1 Or Target.Row = 1 Then ListBox1.Visible = False: Exit Sub
- If Target = "" Then ListBox1.Visible = False: Exit Sub
- Application.EnableEvents = False
- ListBox1.Clear
- ListBox1.Top = Target.Top
- ListBox1.Left = Target.Left + Target.Width
- Rng = Sheets(1).[a1].CurrentRegion
- List = ""
- orng = Sheets("省市县代码对照表").[a1].CurrentRegion
- With Sheets("省市县代码对照表")
- '自治区
- .UsedRange.Replace What:="自治区", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="新区", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="省", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="市", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="地区", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="盟", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="县", Replacement:="", LookAt:=xlPart
- .UsedRange.Replace What:="区", Replacement:="", LookAt:=xlPart
- End With
- Rng = Sheets("省市县代码对照表").[a1].CurrentRegion
- Sheets("省市县代码对照表").[a1].CurrentRegion = orng
- y = Target.Text
- For rr = 2 To UBound(Rng)
- xx = orng(rr, 1) & " | " & orng(rr, 2) & " | " & orng(rr, 3)
- 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
- If InStr(List, xx) = 0 Then ListBox1.AddItem xx:
- List = List & xx & ","
- End If
- Next rr
- For rr = 2 To UBound(Rng)
- xx = orng(rr, 1) & " | " & orng(rr, 2) & " | " & orng(rr, 3)
- 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
- If InStr(List, xx) = 0 Then ListBox1.AddItem xx:
- List = List & xx & ","
- End If
- Next rr
- For rr = 2 To UBound(Rng)
- xx = orng(rr, 1) & " | " & orng(rr, 2) & " | " & orng(rr, 3)
- 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
- If InStr(List, xx) = 0 Then ListBox1.AddItem xx:
- List = List & xx & ","
- End If
- Next rr
- ListBox1.Visible = True
- If List = "" Then
- MsgBox "Not found"
- ListBox1.Visible = False
-
- End If
- Application.EnableEvents = True
- End Sub
复制代码
|
|