代码修改如下:
- Sub lqxs()
- Dim d, Arr, i&, Brr, sf$, dq$, sx$, x$, tt, aa, j%, jj%
- Set d = CreateObject("Scripting.Dictionary")
- Sheet2.Activate
- [h2:j500].ClearContents
- Arr = [a1].CurrentRegion
- Brr = Sheet1.UsedRange
- For i = 1 To UBound(Brr)
- If Brr(i, 1) <> "" Then
- x = Left(Brr(i, 1), 2)
- d(x) = d(x) & i & ","
- End If
- Next
- For i = 2 To UBound(Arr)
- ss = Arr(i, 6)
- If ss <> "" Then
- sf = Left(ss, 2): dq = Left(ss, 4): sx = Left(ss, 6)
- If d.exists(sf) Then
- tt = d(sf): tt = Left(tt, Len(tt) - 1)
- aa = Split(tt, ",")
- Cells(i, 8) = Brr(aa(0), 2)
- For j = 1 To UBound(aa)
- x = Left(Brr(aa(j), 1), 4): dd = 0
- If dq = x Then
- Cells(i, 9) = Brr(aa(j), 2): dd = 1
- For jj = j To UBound(aa)
- x = Left(Brr(aa(jj), 1), 6)
- If sx = x Then
- Cells(i, 10) = Brr(aa(jj), 2): GoTo 100
- End If
- Next
- MsgBox "没有找到市县代码": GoTo 100
- End If
- Next
- If dd = 0 Then MsgBox "没有找到地区代码"
- Else
- MsgBox "地址码错误。"
- End If
- End If
- 100:
- Next
- End Sub
复制代码 |