|
- Private Sub CommandButton1_Click()
- On Error Resume Next '
- Dim arr, d, r, i, j, k, x
- Set d = CreateObject("scripting.dictionary")
- With Sheets("总表")
- arr = .[A1].CurrentRegion
- For i = 2 To UBound(arr)
- x = Month(arr(i, 2)) & "月"
- If Not d.exists(x) Then
- Set d(x) = Union(.[A1].Resize(1, 14), .Cells(i, 1).Resize(1, 14))
- Else
- Set d(x) = Union(d(x), .Cells(i, 1).Resize(1, 14))
- End If
- Next
- End With
- Call 删除工作表
- dk = d.Keys: dt = d.Items
- For i = 0 To UBound(dk)
- Worksheets.Add after:=Sheets(Sheets.Count)
- With ActiveSheet
- .Name = dk(i)
- dt(i).Copy .[A1]
- End With
- Next
- Sheets("总表").Activate
- End Sub
- Private Sub CommandButton2_Click()
- Call 删除工作表
- End Sub
- Sub 删除工作表()
- Application.DisplayAlerts = False
- For Each Sh In Worksheets
- If Sh.Name <> "总表" Then Sh.Delete
- Next
- Application.DisplayAlerts = False
- End Sub
复制代码 |
|