|
纯练手。。。- Sub ykcbf() '//2024.3.13
- Dim wb, arr, sh
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- p = ThisWorkbook.Path & ""
- Set d = CreateObject("Scripting.Dictionary")
- Set sh = ThisWorkbook.Sheets("数据")
- bt = 6 '//标题行数
- With sh
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .UsedRange
- End With
- For i = bt + 1 To UBound(arr)
- s = CStr(arr(i, 1))
- If Val(s) Then
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- d(s)(i) = i
- n = n + 1
- End If
- Next
- For Each k In d.keys
- sh.Copy
- Set wb = ActiveWorkbook
- m = 0
- ReDim brr(1 To d(k).Count, 1 To UBound(arr, 2))
- With wb.Sheets(1)
- .Name = k
- .DrawingObjects.Delete
- .Range("A7:N" & bt + n).ClearContents
- For Each kk In d(k).keys
- m = m + 1
- For j = 1 To UBound(arr, 2)
- brr(m, j) = arr(kk, j)
- Next
- brr(m, 2) = m
- Next
- .Cells(bt + 1, 1).Resize(m, UBound(brr, 2)) = brr
- .Range(.Cells(bt + n + 1, 1), .Cells(bt + n + 6, "M")).Copy
- .Cells(bt + n + 7, 2).Select
- ActiveSheet.Paste
- .Rows(bt + n + 1 & ":" & bt + n + 6).Delete Shift:=xlUp
- Application.CutCopyMode = False
- .Columns("A:A").Delete Shift:=xlToLeft
- .Rows(bt + n + 1 & ":" & bt + n + 1).RowHeight = 25
- End With
- wb.SaveAs p & k
- wb.Close 1
- Next
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|