|
代码如下。。。
Sub test()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
t = Timer
Dim wb As Workbook, sht As Worksheet, sh As Worksheet
Set wb = ThisWorkbook
Set sht = wb.Sheets("人员地址")
Set sh = wb.Sheets("省+地级市+县级市汇总")
arr = sh.[a1].CurrentRegion
brr = sht.[a1].CurrentRegion
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
If Right(arr(i, 2), 1) = "市" Then
s = Left(arr(i, 2), Len(arr(i, 2)) - 1)
If Not d.exists(s) Then
d(s) = arr(i, 1)
End If
End If
Next
Key = d.keys
Item = d.items
For i = 2 To UBound(brr)
For j = 0 To UBound(Key)
If InStr(Left(brr(i, 3), Len(Key(j))), Key(j)) Then
brr(i, 4) = Item(j) & brr(i, 3)
Exit For
End If
Next
If j > UBound(Key) Then brr(i, 4) = brr(i, 3)
Next
Set d = Nothing
sht.[a1].Resize(UBound(brr), UBound(brr, 2)) = brr
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "共耗时:" & Format(Timer - t, "0.0000") & " 秒!!!", 64
End Sub
|
|