试试看- Sub test()
- Dim d, i&, ar, t, br(), r
- Set d = CreateObject("scripting.dictionary")
- ar = Sheet1.Range("a1").CurrentRegion
- ReDim br(1 To UBound(ar), 1 To 3)
- For i = 2 To UBound(ar)
- r = d(Trim(ar(i, 1)))
- If r = "" Then
- r = d.count: d(Trim(ar(i, 1))) = r
- br(r, 1) = ar(i, 1)
- br(r, 2) = ar(i, 2)
- Else
- If br(r, 3) = "" Then
- br(r, 3) = ar(i, 2)
- If br(r, 2) > br(r, 3) Then
- t = br(r, 2): br(r, 2) = br(r, 3): br(r, 3) = t
- End If
- Else
- If ar(i, 2) > br(r, 3) Then
- br(r, 2) = br(r, 3): br(r, 3) = ar(i, 2)
- ElseIf ar(i, 2) > br(r, 2) Then
- br(r, 2) = ar(i, 2)
- End If
- End If
- End If
- Next
- [h2].Resize(d.count, 2) = br
- End Sub
复制代码 |