|
本帖最后由 gwjkkkkk 于 2022-12-4 20:16 编辑
Sub TEST5()
Dim arr, i&, dic As Object
Dim strFirstAddress$, Rng As Range, rngFind As Range, vKey
Set dic = CreateObject("Scripting.Dictionary")
If [B1] = "" Then MsgBox "查询数据为空,请检查!": Exit Sub
arr = Sheets(2).[A1].CurrentRegion
For i = 1 To UBound(arr, 2)
dic(arr(1, i)) = i
Next i
Set Rng = [A3:F100]
For i = UBound(arr) To 2 Step -1
If arr(i, 4) = [B1] Then
For Each vKey In dic.keys
Set rngFind = Rng.Find(vKey, , , xlWhole)
If Not rngFind Is Nothing Then
strFirstAddress = rngFind.Address
Do
rngFind.Offset(, 1) = arr(i, dic(vKey))
Set rngFind = Rng.FindNext(rngFind)
Loop Until rngFind.Address = strFirstAddress
End If
Next
Exit For
End If
Next i
Set dic = Nothing
End Sub
|
|