|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
try this:
Sub zz()
Dim a, d As Object, k, t, b()
Set d = CreateObject("scripting.dictionary")
a = Sheets(1).[a1].CurrentRegion.Value
For i = 2 To UBound(a)
k = a(i, 1) & "|" & a(i, 2) & "|" & a(i, 3) & "|" & a(i, 4)
If d.exists(k) Then
t = d(k): t(0) = IIf(t(0) > a(i, 5), t(0), a(i, 5))
d(k) = Array(t(0), i)
Else
d(k) = Array(a(i, 5), i)
End If
Next
a = Sheets(2).[a1].CurrentRegion.Value
ReDim b(1 To UBound(a) - 1, 1 To 2)
For i = 2 To UBound(a)
k = a(i, 1) & "|" & a(i, 2) & "|" & a(i, 3) & "|" & a(i, 4)
b(i - 1, 1) = d(k)(0): b(i - 1, 2) = d(k)(1)
Next
Sheets(2).[e2].Resize(UBound(b), 2) = b
End Sub |
|