|
参与一下。。。- Sub ykcbf() '//2024.1.17
- Dim arr, d
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- With Sheets("模板")
- r = .Cells(.Rows.Count, "a").End(xlUp).Row
- Set Rng = .Range("a2:e" & r)
- With Rng
- .Parent.Sort.SortFields.Clear
- .Sort Key1:=.Item(1), Order1:=1, Key2:=.Item(2), Order2:=1, Header:=2
- End With
- arr = .[a1].Resize(r, 5)
- For i = 2 To UBound(arr)
- s = arr(i, 1) & "|" & arr(i, 2)
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- d(s)(i) = i
- Next
- ReDim brr(1 To d.Count, 1 To 100)
- For Each k In d.keys
- m = m + 1
- brr(m, 1) = Split(k, "|")(0)
- brr(m, 2) = Split(k, "|")(1)
- c = 2
- For Each kk In d(k).keys
- For x = 1 To 3
- c = c + 1
- brr(m, c) = arr(kk, x + 2)
- Next
- Next
- Max = IIf(Max < c, c, Max)
- Next
- .[i3:az1000].Clear
- .[k1:az1000].UnMerge
- .[i3].Resize(m, Max) = brr
- .[i1].Resize(m + 2, Max).HorizontalAlignment = xlCenter
- .[i1].Resize(m + 2, Max).VerticalAlignment = xlCenter
- .[i1].Resize(m + 2, Max).Borders.LineStyle = 1
- .[i3].Resize(m, Max).ShrinkToFit = True
- col = 8
- For y = col + 3 To Max + col Step 3
- p = p + 1
- .Cells(1, y).Resize(1, 3) = "荣誉" & p
- .Cells(1, y).Resize(1, 3).Merge
- .Cells(2, y) = "获奖时间"
- .Cells(2, y + 1) = "奖励内容"
- .Cells(2, y + 2) = "奖励名词"
- Next
- .Range(.Cells(1, col + 3), .Cells(1, Max + col)).Cells.Interior.ColorIndex = 4
- .Range(.Cells(2, col + 3), .Cells(2, Max + col)).Cells.Interior.ColorIndex = 6
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|