|
总表拆分- Sub ykcbf() '//2024.8.21 总表拆分
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim tm: tm = Timer
- Dim arr, brr, b, d
- Set d = CreateObject("scripting.dictionary")
- Set fso = CreateObject("Scripting.FileSystemObject")
- p = ThisWorkbook.Path & ""
- Set sh = ThisWorkbook.Sheets("清单")
- c = 13 '//拆分列号
- With sh
- r = .Cells(.Rows.Count, c).End(xlUp).Row
- arr = .Range("a1:y" & r)
- End With
- For i = 3 To UBound(arr)
- s = arr(i, c)
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- d(s)(i) = i
- Next
- On Error Resume Next
- fn = "总表拆分表_"
- For Each k In d.keys
- m = 0
- ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
- Sheets("模板").Copy
- Set wb = ActiveWorkbook
- With wb.Sheets(1)
- .[m2] = CDate(Date)
- .DrawingObjects.Delete
- For Each kk In d(k).keys
- m = m + 1
- brr(m, 1) = m
- For j = 2 To 12
- brr(m, j) = arr(kk, j)
- Next
- brr(m, 13) = arr(kk, 15)
- brr(m, 14) = arr(kk, 16)
- brr(m, 15) = arr(kk, 18)
- brr(m, 16) = arr(kk, 23)
- brr(m, 17) = arr(kk, 24)
- Next
- If m > 6 Then
- For i = 1 To m - 6
- Cells(5 + i, 1).EntireRow.Insert
- Next i
- End If
- .[a4].Resize(m, 17) = brr
- r1 = IIf(m <= 6, 10, 4 + m)
- .Cells(r1, "n") = Application.Sum(.Cells(4, "q").Resize(m))
- rmb = .Cells(r1, "n").Value
- .Cells(r1, "d").Value = RmbDx(rmb)
- End With
- wb.SaveAs p & fn & k
- wb.Close
- Next
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "拆分完毕,共用时: " & Format(Timer - tm, "0.000秒"), , "提示"
- End Sub
复制代码
|
|