|
我是用正则表达式做的,准确率高,但不能模糊匹配,供参考。- Sub test()
- Dim reg1 As Object
- Dim arr1, arr2
- Dim r1, r2, i, j As Integer
-
-
- Set reg1 = CreateObject("vbscript.regexp")
- arr1 = Worksheets("省市县代码对照表").UsedRange
- arr2 = Worksheets("账户信息").UsedRange
-
- r1 = UBound(arr1)
- r2 = UBound(arr2)
-
-
- reg1.Global = False
-
- fla = False
-
- For i = 2 To r2
- fla = False
- For j = 2 To r1
- reg1.Pattern = arr1(j, 4)
- If reg1.test(arr2(i, 1)) Then
- arr2(i, 3) = arr1(j, 2) & arr1(j, 3) & arr1(j, 4)
- Exit For
- Else
- arr2(i, 3) = ""
- End If
- Next
-
- Next
-
- Worksheets("账户信息").Range("c1").Resize(r2, 1) = Application.Index(arr2, 0, 3)
-
- End Sub
复制代码 |
评分
-
5
查看全部评分
-
|