|
楼主 |
发表于 2016-5-19 09:09
|
显示全部楼层
Sub test()
If Not flag Then Call createIndex
sens = Join(sen.Keys, "|")
shis = Join(shi.Keys, "|")
arr = Sheet2.Range("A1").CurrentRegion.Resize(, 8).Offset(1)
r = UBound(arr)
Set reg1 = CreateObject("vbscript.regexp")
reg1.Global = True
reg1.Pattern = sens
Set reg2 = CreateObject("vbscript.regexp")
reg2.Global = True
reg2.Pattern = shis
brr = Sheet1.Range("A1").CurrentRegion.Resize(, 1)
ReDim crr(1 To UBound(brr), 1 To 2)
crr(1, 1) = "省、市、区县": crr(1, 2) = "街道栋号"
For i = 2 To UBound(brr)
sid = ""
star = 1: send = r
If reg1.test(brr(i, 1)) Then
Set matches = reg1.Execute(brr(i, 1))
sid = sen(matches(0).Value)
End If
If reg2.test(brr(i, 1)) Then
Set matches = reg2.Execute(brr(i, 1))
sid = shi(matches(0).Value)
End If
If sid <> "" Then
starend = Split(sid, "|")
star = starend(0):
send = starend(1)
End If
For j = star To send
If Len(arr(j, 7)) Then
n = InStr(brr(i, 1), arr(j, 7))
If n Then
tmpstr = ""
For k = 3 To 8
tmpstr = tmpstr & arr(j, k)
If k = 4 Or k = 6 Then tmpstr = tmpstr & " "
Next
crr(i, 1) = tmpstr
crr(i, 2) = brr(i, 1)
Do While n > 0
crr(i, 2) = Mid(crr(i, 2), n + Len(arr(j, 7)))
Select Case Left(crr(i, 2), 1)
Case "市", "区", "县", "州"
crr(i, 2) = Mid(crr(i, 2), 2)
Case "自"
crr(i, 2) = Mid(crr(i, 2), 4)
Case Else
End Select
n = InStr(crr(i, 2), arr(j, 7))
Loop
End If
End If
Next
Next
Sheet1.Range("A1").CurrentRegion.Resize(, 2).Offset(, 1) = crr
End Sub
|
|