|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub test0()
Dim ar, dict As Object, wks As Worksheet, ran As Range
Dim rowsHeight() As Double, strKey As String
Dim i As Long, j As Long, titleRow As Long, splitCol As Long
titleRow = 3 '标题所在 行
splitCol = 8 '拆分依据 列
DoApp False
Set dict = CreateObject("Scripting.Dictionary")
ar = Array("总表", "统计表", "封面") '不必删除的 工作表 在这里列出来
For j = 0 To UBound(ar)
dict.Add ar(j), ""
Next
For Each wks In Worksheets
If Not dict.Exists(wks.Name) Then wks.Delete
Next
dict.RemoveAll
ReDim rowsHeight(1 To titleRow + 1)
With Worksheets("总表")
For j = 1 To UBound(rowsHeight)
rowsHeight(j) = .Rows(j).RowHeight
Next
With .Range("A1").CurrentRegion
ar = .Value
Set ran = .Resize(titleRow)
End With
For i = titleRow + 1 To UBound(ar) '- 1
strKey = Trim(ar(i, splitCol))
If Len(strKey) Then
If Not dict.Exists(strKey) Then Set dict(strKey) = ran
Set dict(strKey) = Union(dict(strKey), .Range("A" & i).Resize(, UBound(ar, 2)))
End If
Next
End With
For j = 0 To dict.Count - 1
With Worksheets.Add(After:=Worksheets(Worksheets.Count))
ran.Copy
.Range("A1").PasteSpecial xlPasteColumnWidths
dict.Items()(j).Copy .Range("A1")
For i = 1 To UBound(rowsHeight) - 1
.Rows(i).RowHeight = rowsHeight(i)
Next
.Rows(i & ":" & .Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row).RowHeight = rowsHeight(i)
.Name = dict.Keys()(j)
.DrawingObjects.Delete
End With
Next
Worksheets("总表").Activate
Set ran = Nothing
Set dict = Nothing
DoApp
Beep
End Sub
Function DoApp(Optional b As Boolean = True)
With Application
.ScreenUpdating = b
.DisplayAlerts = b
.Calculation = -b * 30 - 4135
End With
End Function |
|