Option Explicit
Sub TEST7()
Dim ar, br, i&, j&, k&, p&, dic As Object, t#
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
t = Timer
With [A1].CurrentRegion
.Offset(1, 2).Clear
ar = .Value
For i = 1 To UBound(ar, 2): dic(ar(1, i)) = i: Next
End With
br = Sheets(2).[A1].CurrentRegion
For i = 2 To UBound(ar)
For j = 2 To UBound(br)
If br(j, 1) = ar(i, 1) Then
For k = 2 To UBound(br, 2)
If dic.exists(br(1, k)) Then
p = dic(br(1, k))
ar(i, p) = br(j, k)
End If
Next k
Exit For
End If
Next j
Next i
[A1].Resize(UBound(ar), UBound(ar, 2)) = ar
Set dic = Nothing
Application.ScreenUpdating = True
MsgBox "执行完毕!_用时: " & Format(Timer - t, "0.00") & " 秒", 64
End Sub |