|
- Sub test()
- Dim r%, i%
- Dim arr, brr, crr(), drr()
- Dim d As Object
- Dim rng As Range
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("原始表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- .Range("a2:f" & r).Interior.ColorIndex = 0
- arr = .Range("a2:f" & r)
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 2)) Then
- Set d(arr(i, 2)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 2)).exists(arr(i, 4)) Then
- m = 1
- ReDim brr(1 To m)
- Else
- brr = d(arr(i, 2))(arr(i, 4))
- m = UBound(brr) + 1
- ReDim Preserve brr(1 To m)
- End If
- brr(m) = i
- d(arr(i, 2))(arr(i, 4)) = brr
- Next
- For Each aa In d.keys
- ReDim crr(1 To 3)
- y = 0
- s = 1
- For Each bb In d(aa).keys
- brr = d(aa)(bb)
- For i = 2 To UBound(brr)
- .Cells(brr(i) + 1, 1).Resize(1, 6).Interior.ColorIndex = 6
- Next
- For i = 1 To UBound(brr)
- arr(brr(i), 6) = i
- Next
- crr(1) = crr(1) + UBound(brr)
- crr(2) = crr(2) & ";" & bb & UBound(brr)
- If UBound(brr) > 1 Then
- crr(3) = crr(3) & ";" & aa & "," & bb & "," & UBound(brr) & "(" & Join(brr, ",") & ")"
- End If
- If UBound(brr) > 1 Then
- y = y + 1
- ReDim Preserve drr(1 To y)
- drr(y) = Array(s, Len(bb) + Len(CStr(UBound(brr))))
- End If
- s = s + Len(bb) + Len(CStr(UBound(brr))) + 1
-
- Next
- If Len(crr(2)) <> 0 Then
- crr(2) = Mid(crr(2), 2)
- End If
- If Len(crr(3)) <> 0 Then
- crr(3) = Mid(crr(3), 2)
- End If
- m = d(aa).items()(0)(1) + 1
- .Cells(m, 7).Resize(1, UBound(crr)) = crr
- If y > 0 Then
- For k = 1 To UBound(drr)
- .Cells(m, 8).Characters(Start:=drr(k)(0), Length:=drr(k)(1)).Font.ColorIndex = 3
- Next
- End If
-
- Next
- .Range("f2").Resize(UBound(arr), 1) = Application.Index(arr, 0, 6)
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|