|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub 删除小计和合计()
- Sheet2.Activate
- Dim rng As Range, i&, r&
- r = Cells(Rows.Count, 1).End(3).Row
- If Cells(r, 2) <> "合计" Then Exit Sub
- Set rng = Rows(r - 1)
- For i = 6 To r
- If InStr(Cells(i, 2), "计") > 0 Then
- Set rng = Union(rng, Rows(i))
- End If
- Next
- rng.EntireRow.Delete
- End Sub
- Sub 插入小计和合计()
- Application.ScreenUpdating = False
- Sheet2.Activate
- Dim rng As Range, c, i&, k&, r&
- r = Cells(Rows.Count, 1).End(3).Row
- If Cells(r, 2) = "合计" Then Exit Sub
- Cells(r + 2, 2) = "合计"
- Cells(r + 2, 1) = r - 5 & "笔"
- Cells(r + 1, 1).Resize(2, 20).Borders.LineStyle = 1
- Cells(r + 2, 1).Resize(1, 20).Interior.ColorIndex = 40
- k = 1
- For i = 7 To r * 2
- If Cells(i, 2) = "合计" Then Exit For
- If Left(Cells(i, 1), 3) = Left(Cells(i - 1, 1), 3) Then
- k = k + 1
- Else
- Rows(i).Insert
- r = r + 1
- Cells(i, 2) = "小计"
- Cells(i, 1) = k & "笔"
- For Each c In Array(7, 14, 15)
- Cells(i, c) = Application.Sum(Cells(i - k, c).Resize(k))
- Cells(r + 2, c) = Cells(r + 2, c) + Cells(i, c)
- Next
- Cells(i, 1).Resize(1, 20).Interior.ColorIndex = 35
- k = 1: i = i + 1
- End If
- Next
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|