用如何代码可实现,假设原数据在A、B列
Sub main()
Set dic = CreateObject("scripting.dictionary")
arr = Range("A1").CurrentRegion
For i = 1 To UBound(arr)
If dic.exists(arr(i, 2)) = False Then
dic(arr(i, 2)) = arr(i, 1)
Else
If dic(arr(i, 2)) < arr(i, 1) Then
dic.Remove arr(i, 2)
dic(arr(i, 2)) = arr(i, 1)
End If
End If
Next i
[E1].Resize(dic.Count, 1) = Application.Transpose(dic.keys)
[D1].Resize(dic.Count, 1) = Application.Transpose(dic.items)
End Sub
详细步骤如下: