|
不要另外写代码,加到一起处理吧:
- Sub 拆分为工作表()
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- For Each sh In Worksheets
- If sh.Name <> "模板" And sh.Name <> "Sheet1" Then sh.Delete
- Next
- Sheet1.Range("A2:G" & Sheet1.Range("B65536").End(xlUp).Row).Sort Key1:=Range("B1"), Order1:=xlAscending
- n = 2
- With ThisWorkbook.Sheets("Sheet1")
- For Each b In .Range("B2:B" & .Range("B65536").End(xlUp).Row)
- u = b.Row
- If b <> b.Offset(1, 0) Then
- Sheets("模板").Copy After:=Sheets(Worksheets.Count)
- .Rows(n & ":" & u).Copy Sheets(Sheets.Count).Range("a4")
- Sheets(Sheets.Count).Name = Format(b, "m月d日")
- n = u + 1
- End If
- Next
- End With
- For Each sh In Sheets
- If sh.Name <> "模板" And sh.Name <> "Sheet1" Then
- With sh
- k = .Range("a65536").End(xlUp).Row
- arr = .UsedRange
- For i = 4 To UBound(arr)
- For j = 5 To 7
- If IsNumeric(.Cells(i, j)) Then
- .Cells(k - 3, j) = Application.Sum(Application.Index(arr, , j))
- End If
- Next
- Next
- For k = 4 To 10
- If .Cells(k, 2) = "" Then
- .Rows(k).Hidden = True
- Else
- .Rows(k).Hidden = False
- End If
- Next
- End With
- End If
- Next
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|