|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
完善一下上面老师的代码:
- Private Sub CommandButton1_Click()
- Application.ScreenUpdating = False
- Dim x, i, j As Integer
- Dim hj(1 To 5)
- For x = 2 To Range("b65536").End(xlUp).Row '删除小计行
- If Cells(x, 2) = "小计" Then
- Rows(x).Delete 'Cells(x, 1).EntireRow.Delete
- End If
- Next
- Columns("a:h").Sort key1:=[b1], order1:=1, Header:=xlYes '排序
- i = 2 '初始值i
- Do
- If Cells(i, 2) = Cells(i + 1, 2) Then 'B列上下行内容相同时,分别对D~H列单元格累计
- For j = 1 To 5
- hj(j) = hj(j) + Cells(i, j + 3)
- Next
- i = i + 1
- Else '否则,在下1行插入一空行
- For j = 1 To 5
- hj(j) = hj(j) + Cells(i, j + 3)
- Next
- Cells(i + 1, 1).EntireRow.Insert '在下1行插入一空行
- Cells(i + 1, 2) = "小计" 'B列单元格="小计"
- For j = 1 To 5
- Cells(i + 1, j + 3) = hj(j) '把合计值赋予小计行的单元格
- Next
- Cells(i + 1, 1).Resize(1, 8).Interior.ColorIndex = 6 '底色标黄
- i = i + 2
- For j = 1 To 5
- hj(j) = 0
- Next
- End If
- Loop While Cells(i, 4) <> ""
- Application.ScreenUpdating = True
- [a1].CurrentRegion.Borders.LineStyle = 1
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|