|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:e" & r)
- End With
- n = 2
- For i = 1 To UBound(arr)
- If Not d1.exists(arr(i, 3)) Then
- n = n + 1
- d1(arr(i, 3)) = n
- End If
- Next
- ls = 2 + d1.Count
- For i = 1 To UBound(arr)
- xm = arr(i, 4) & "+" & arr(i, 1)
- If Not d.exists(xm) Then
- ReDim brr(1 To ls)
- brr(1) = arr(i, 4)
- brr(2) = arr(i, 1)
- Else
- brr = d(xm)
- End If
- n = d1(arr(i, 3))
- If brr(n) = Empty Then
- brr(n) = i
- Else
- If arr(brr(n), 5) < arr(i, 5) Then
- n = i
- End If
- End If
- d(xm) = brr
- Next
- ReDim crr(1 To d.Count, 1 To ls)
- m = 0
- For Each aa In d.keys
- brr = d(aa)
- For j = 3 To UBound(brr)
- If brr(j) <> Empty Then
- brr(j) = arr(brr(j), 2)
- End If
- Next
- m = m + 1
- For j = 1 To UBound(brr)
- crr(m, j) = brr(j)
- Next
- Next
- With Worksheets("sheet2")
- .Cells.Clear
- .Range("a1:b1") = Array("Group2", "LocnID")
- For j = 1 To 2
- .Cells(1, j).Resize(2, 1).Merge
- Next
- With .Range("c1").Resize(1, d1.Count)
- .Merge
- .Value = "TenderID"
- End With
- .Range("c2").Resize(1, d1.Count) = d1.keys
- .Range("a3").Resize(UBound(crr), UBound(crr, 2)) = crr
- With .Range("a1").Resize(2 + UBound(crr), ls)
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 10
- End With
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
-
- End With
- End Sub
复制代码 |
|