|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub Sorting() '拆分
Dim arr, xD, s#, n%, i&, i2&
Application.ScreenUpdating = False: Application.DisplayAlerts = False
On Error Resume Next
Tm = Timer
Set TWK = ThisWorkbook
arr = Sheets(1).[A1].CurrentRegion
Set xD = CreateObject("scripting.dictionary")
For i = 4 To UBound(arr)
If xD.exists(arr(i, 2)) Then
Set xD(arr(i, 2)) = Union(xD(arr(i, 2)), Rows(i))
Else
Set xD(arr(i, 2)) = Union(Rows(2), Rows(3), Rows(i))
End If
Next
Workbooks.Add
For i = Sheets.Count To 2 Step -1
Sheets(i).Delete
Next
For i = 0 To xD.Count - 1
With Sheets(i + 1)
xD.items()(i).Copy Sheets(i + 1).[A1]
.Name = xD.keys()(i)
.Columns("A:V").Columns.AutoFit
.[A1].CurrentRegion.Offset(2, 0).RowHeight = 28
End With
If Sheets.Count < xD.Count Then ActiveWorkbook.Sheets.Add AFTER:=Sheets(Sheets.Count)
Next
For i = 1 To Sheets.Count
With Sheets(i)
.Rows("1:1").Insert
.[A1] = arr(1, 1) '"月 度 采 购 计 划 汇 总 表"
.[A1].Font.Size = 22
.[A1].RowHeight = 50
.Columns("S:S").ColumnWidth = 8
.Range(.Cells(1, 1), .Cells(1, 22)).MergeCells = True
.Range(.Cells(1, 1), .Cells(1, 22)).HorizontalAlignment = xlCenter
arr = .[A1].CurrentRegion
For i2 = 4 To UBound(arr)
n = n + 1
arr(i2, 1) = n
s = s + arr(i2, 20)
Next
.Range("a1").Resize(UBound(arr), 1) = arr
.Cells(n + 4, 19) = "合 计"
.Cells(n + 4, 19).HorizontalAlignment = xlCenter
.Cells(n + 4, 20) = s
.Cells(n + 4, 20).NumberFormatLocal = "0.00"
.Range(.Cells(n + 4, 1), .Cells(n + 4, 22)).Borders.LineStyle = xlContinuous
.Columns("J:J").ColumnWidth = 14
.Columns("m:n").ColumnWidth = 14
n = 0: s = 0
End With
Next
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & "采购明细拆分"
Application.ScreenUpdating = True: Application.DisplayAlerts = True
MsgBox "用时: " & Round(Timer - Tm, 2) & "秒"
End Sub
|
|