|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Set reg = CreateObject("vbscript.regexp")
- With reg
- .Global = True
- .Pattern = "(\S+[省市县区乡])"
- End With
- With Sheets("省市县代码对照表")
- brr = .UsedRange
- End With
- With Sheets("账户信息")
- arr = .UsedRange
- For i = 2 To UBound(arr)
- Set mat = reg.Execute(arr(i, 1))
- If mat.Count > 0 Then
- For j = 2 To UBound(brr)
- S = brr(j, 2) & brr(j, 3) & brr(j, 4) & brr(j, 2) & brr(j, 4) & brr(j, 3)
- m = mat(0)
- If InStr(S, m) > 0 Then
- arr(i, 4) = brr(j, 2) & brr(j, 3)
- m2 = Left(brr(j, 4), Len(brr(j, 4)) - 1)
- If InStr(m2, m) > 0 Or InStr(m, m2) > 0 Then
- arr(i, 5) = brr(j, 4)
- End If
- End If
- Next
- End If
- Next
- .UsedRange.Offset(1, 3).ClearContents
- .[a1].Resize(UBound(arr), UBound(arr, 2)) = arr
- End With
- End Sub
复制代码 |
|