|
- 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)
- n = 1
- For i = 1 To UBound(arr)
- If Not d1.exists(arr(i, 5)) Then
- n = n + 1
- d1(arr(i, 5)) = n
- End If
- Next
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 4)) Then
- ReDim brr(1 To d1.Count + 1)
- brr(1) = arr(i, 4)
- Else
- brr = d(arr(i, 4))
- End If
- n = d1(arr(i, 5))
- If IsEmpty(brr(n)) Then
- brr(n) = arr(i, 2)
- Else
- brr(n) = arr(i, 2) & "、" & arr(i, 2)
- End If
- d(arr(i, 4)) = brr
- Next
- End With
- With Worksheets("sheet2")
- .Cells.Clear
- .Range("a1") = "班级"
- .Range("b1").Resize(1, d1.Count) = d1.keys
- .Range("a2").Resize(d.Count, UBound(brr)) = Application.Transpose(Application.Transpose(d.items))
- With .Range("a1").Resize(1, UBound(brr))
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- With .Range("a1").Resize(1 + d.Count, UBound(brr))
- .Borders.LineStyle = xlContinuous
- End With
- End With
- End Sub
复制代码 |
|