|
Sub lsc()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set d = CreateObject("scripting.dictionary")
With Sheet1
arr = .UsedRange
For i = 2 To UBound(arr)
s = Month(arr(i, 1))
If Not d.exists(s) Then
Set d(s) = .[a1:h1]
End If
Set d(s) = Union(d(s), .Cells(i, 1).Resize(1, 8))
Next
End With
For Each sht In Worksheets
If sht.Name <> "费用汇总" Then
sht.Delete
End If
Next
For Each c In d.keys
Set sht = Worksheets.Add(after:=Worksheets(Worksheets.Count))
With sht
For j = 1 To UBound(arr, 2)
.Columns(j).ColumnWidth = Sheet1.Columns(j).ColumnWidth
Next
.Name = CStr(c) & "月"
d(c).Copy .[a1]
End With
Next
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub |
|