|
- Sub test()
- Dim d As Object
- Dim r%, i%
- Dim arr, brr
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:d" & r)
- For i = 1 To UBound(arr)
- For j = 3 To 4
- If Len(arr(i, j)) <> 0 Then
- If Not d.Exists(arr(i, 1)) Then
- m = 1
- ReDim brr(1 To 2, 1 To m)
- Else
- brr = d(arr(i, 1))
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 2, 1 To m)
- End If
- brr(1, m) = Day(arr(i, 2))
- brr(2, m) = j
- d(arr(i, 1)) = brr
- End If
- Next
- Next
- End With
- For Each aa In d.Keys
- brr = d(aa)
- For i = 1 To UBound(brr, 2) - 1
- p = i
- For j = i + 1 To UBound(brr, 2)
- If brr(1, p) > brr(1, j) Then
- p = j
- End If
- Next
- If p <> i Then
- temp1 = brr(1, i)
- temp2 = brr(2, i)
- brr(1, i) = brr(1, p)
- brr(2, i) = brr(2, p)
- brr(1, p) = temp1
- brr(2, p) = temp2
- End If
- Next
- d(aa) = brr
- Next
- m = 2
- With Worksheets("sheet1")
- For Each aa In d.Keys
- arr = Application.Index(d(aa), 2, 0)
- brr = Application.Index(d(aa), 1, 0)
- ReDim crr(0 To UBound(brr))
- s = 1
- For i = 1 To UBound(brr)
- crr(i) = s
- s = s + Len(brr(i)) + 1
- Next
- .Cells(m, 7) = aa
- .Cells(m, 8) = Join(brr, ",")
- For i = 1 To UBound(brr)
- If arr(i) = 4 Then
- With .Cells(m, 8).Characters(Start:=crr(i), Length:=Len(brr(i)) + 1).Font
- .Underline = xlUnderlineStyleSingle
- .ColorIndex = 5
- End With
- End If
- Next
- m = m + 1
- Next
- End With
- tt = d.Items
- End Sub
复制代码 |
|