提取唯一列表&找到最大值

时间:2017-08-05 03:44:56

标签: excel vba

此代码尝试使用其最大值创建唯一名称列表,但是if Not Exists存在一些错误。你能帮我解决这个问题吗?

Sub UniqeMAX() 

Dim Rng As Range
Dim Dn As Range

Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))

With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare

For Each Dn In Rng

If Not.Exists(Dn.Value) Then

.Add Dn.Value, Dn(, 3)
 Else
 .Item(Dn.Value) = Application.max(.Item(Dn.Value), Dn(, 3))

End If
Next

Range("D1").Resize(.Count, 3) = Application.Transpose(Array(.Keys, .Items))

End With
End Sub

0 个答案:

没有答案