|
参与一下。。。
- Sub ykcbf() '//2024.9.11
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- For Each sht In Sheets
- If sht.Name = "打印" Then sht.Delete
- Next
- Sheets.Add(After:=Sheets(Sheets.Count)).Name = "打印"
- arr = Sheets("字典").UsedRange
- For i = 2 To UBound(arr)
- s = arr(i, 1)
- d1(s) = arr(i, 2)
- Next
- With Sheets("名单")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .[a1].Resize(r, 4)
- End With
- For i = 2 To UBound(arr)
- s = arr(i, 2)
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- d(s)(i) = ""
- Next
- With Sheets("打印")
- For Each k In d.keys
- n = n + 1
- m = 0
- ReDim brr(1 To d(k).Count, 1 To 2)
- If n = 1 Then
- r = 1
- Sheets("记录样表").Cells.Copy .Cells(r, 1)
- Else
- r = .Cells(Rows.Count, 1).End(3).Row + 2
- Sheets("记录样表").Rows("1:16").Copy .Cells(r, 1)
- End If
- For Each kk In d(k).keys
- m = m + 1
- brr(m, 1) = m
- brr(m, 2) = arr(kk, 3)
- Next
- If m > 11 Then
- For i = 1 To m - 11
- .Cells(r + 5 + i, 1).EntireRow.Insert
- Next i
- Else
- .UsedRange.Offset(r + m + 4).Clear
- End If
- .Cells(r + 4, 1).Resize(m, 2) = brr
- .Cells(r + 1, 3) = k: .Cells(r + 1, "n") = d1(k)
- Next
- End With
- Sheets("名单").Activate
- Set d = Nothing
- Set d1 = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|