|
- 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
- c = .Cells(3, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a3").Resize(r - 2, c)
- End With
- s = 0
- For i = 3 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then
- Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- For j = 2 To UBound(arr, 2)
- If Not d(arr(i, 1)).exists(arr(1, j)) Then
- s = s + 1
- ReDim brr(1 To 6)
- brr(1) = arr(i, 1)
- brr(2) = arr(1, j)
- Else
- brr = d(arr(i, 1))(arr(1, j))
- End If
- If brr(3) = Empty Then
- brr(3) = arr(2, j)
- brr(4) = arr(i, j)
- Else
- If brr(4) > arr(i, j) Then
- brr(3) = arr(2, j)
- brr(4) = arr(i, j)
- End If
- End If
- If brr(5) = Empty Then
- brr(5) = arr(2, j)
- brr(6) = arr(i, j)
- Else
- If brr(6) < arr(i, j) Then
- brr(5) = arr(2, j)
- brr(6) = arr(i, j)
- End If
- End If
- d(arr(i, 1))(arr(1, j)) = brr
- Next
- Next
- m = 0
- ReDim crr(1 To s, 1 To 6)
- For Each aa In d.keys
- For Each bb In d(aa).keys
- m = m + 1
- brr = d(aa)(bb)
- For j = 1 To UBound(brr)
- crr(m, j) = brr(j)
- Next
- Next
- Next
- With Worksheets("sheet2")
- .UsedRange.Offset(2, 0).Clear
- .Range("a3").Resize(UBound(crr), UBound(crr, 2)) = crr
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
-
- End Sub
复制代码 |
|