- Public Sub abc()
- Dim ar, br, cr(), i, str, rep, it, k, tmp, strall
- Dim d As Object
- Set d = CreateObject("Scripting.Dictionary")
- Set rep = CreateObject("vbscript.regexp")
- rep.Global = True
- ar = Range([j2], [k65536].End(3))
- br = Range([b3], [b65536].End(3))
- ReDim cr(1 To UBound(br), 1 To 2)
- For i = 1 To UBound(ar) - 1
- If InStr(ar(i, 2), "地区") > 0 Or InStr(ar(i, 2), "自治州") > 0 Or (Right(ar(i, 2), 1) = "市" And Right(ar(i + 1, 2), 1) = "区") Then
- str = ar(i, 2)
- d(Left(ar(i, 2), 2)) = str
- Else
- If ar(i, 2) <> ar(i, 1) Then d(Left(ar(i, 2), 2)) = str
- End If
- If ar(i, 2) <> ar(i, 1) And ar(i, 2) <> "市辖区" Then
- If Len(ar(i, 2)) > 2 Then
- tmp = Replace(Replace(ar(i, 2), "市", ""), "县", "")
- ElseIf Len(ar(i, 2)) = 2 Then
- tmp = ar(i, 2)
- End If
- strall = strall & IIf(strall = "", "", "|") & tmp
- End If
- Next
- d(ar(UBound(ar), 2)) = str
- it = d.items: k = d.keys
- For i = 1 To UBound(br)
- rep.Pattern = "^(北京[市]*|上海[市]*|天津[市]*|重庆[市]*|河北[省]*|山西[省]*|辽宁[省]*|吉林[省]*|黑龙江[省]*|江苏[省]*|浙江[省]*|安徽[省]*|福建[省]*|江西[省]*|山东[省]*|河南[省]*|湖北[省]*|湖南[省]*|广东[省]*|海南[省]*|四川[省]*|贵州[省]*|云南[省]*|陕西[省]*|甘肃[省]*|青海[省]*|西藏[自治区]*|内蒙古[自治区]*|广西[壮族自治区]*|宁夏[回族自治区]*|新疆[维吾尔自治区]*)"
- str = rep.Replace(br(i, 1), "")
- If d.exists(Left(str, 2)) Then
- cr(i, 2) = d(Left(str, 2))
- cr(i, 1) = [k:k].Find(d(Left(str, 2)), , , 1).Offset(, -1)
- Else
- rep.Pattern = "..(市|县)"
- If rep.test(str) = True Then
- tmp = rep.Execute(str)(0)
- If Not [k:k].Find(tmp, , , 2) Is Nothing Then
- tmp = [k:k].Find(tmp, , , 2)
- cr(i, 2) = d(Left(tmp, 2))
- cr(i, 1) = [k:k].Find(cr(i, 2), , , 1).Offset(, -1)
- End If
- End If
- End If
- If cr(i, 2) = "" Then
- rep.Pattern = "北京|上海|天津|重庆|香港|澳门"
- If rep.test(br(i, 1)) = True Then
- cr(i, 2) = rep.Execute(br(i, 1))(0)
- cr(i, 1) = cr(i, 2)
- End If
- End If
- If cr(i, 2) = "" Then
- rep.Pattern = strall
- If rep.test(br(i, 1)) = True Then
- cr(i, 2) = d(Left(rep.Execute(br(i, 1))(0), 2))
- If rep.Execute(br(i, 1)).Count > 1 Then
- If rep.Execute(br(i, 1))(0) <> rep.Execute(br(i, 1))(1) Then cr(i, 2) = cr(i, 2) & "*"
- End If
- cr(i, 1) = [k:k].Find(cr(i, 2), , , 1).Offset(, -1)
- End If
- End If
- Next
- [f3].Resize(i - 1, 2) = cr
- End Sub
复制代码
|