|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:b" & r)
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 2)) Then
- ReDim brr(1 To 2)
- brr(1) = arr(i, 1)
- brr(2) = arr(i, 1)
- Else
- brr = d(arr(i, 2))
- If brr(1) < arr(i, 1) Then
- brr(1) = arr(i, 1)
- End If
- If brr(2) > arr(i, 1) Then
- brr(2) = arr(i, 1)
- End If
- End If
- d(arr(i, 2)) = brr
- Next
- .Range("f3:j4").ClearContents
- arr = .Range("f2:j4")
- For j = 1 To UBound(arr, 2)
- If d.exists(arr(1, j)) Then
- brr = d(arr(1, j))
- arr(2, j) = brr(1)
- arr(3, j) = brr(2)
- End If
- Next
- .Range("f2:j4") = arr
- End With
- End Sub
复制代码 |
|