Dim x As Integer, m1, m2, k, n
x = 1
Do
x = x + 1
If Cells(x, 1) <> Cells(x - 1, 1) Then m1 = x
If Cells(x, 1) <> Cells(x + 1, 1) Then m2 = x
If m1 <> "" And m2 <> "" Then
Rows(x + 1).Insert
Cells(x + 1, "c") = "小计" 'C列输入“小计”
Cells(x + 1, "f") = Application.Sum(Range(Cells(m1, "f"), Cells(m2, "f")))
k = k + Cells(x + 1, "f")
Cells(x + 1, "h") = Application.Sum(Range(Cells(m1, "h"), Cells(m2, "h")))
n = n + Cells(x + 1, "h")
With Range("A" & x + 1 & ":h" & x + 1)
.Font.Bold = True
.Font.Italic = True
.Interior.Color = 6750207
m1 = ""
m2 = ""
x = x + 1
End With
End If
If Cells(x + 1, 1) = "" Then Exit Do
Loop
Cells(x + 1, "c") = "总计"
Cells(x + 1, "f") = k
Cells(x + 1, "h") = n
With Range("A" & x + 1 & ":h" & x + 1)
.Font.Bold = True
.Font.Italic = True
.Interior.Color = 5296274
End With
End Sub
步骤1 :在最前面插入一列,在2至6行输入1,7至11行输入2.然后先取A2:A11,双击右下角向下填充,填充方式为复制单元格。
步骤2:选取整个数据表,数据 - 分类汇总 ,在打开的分类汇总窗口中,汇总项选数量和金额。另外还要选中“每组数据分页”的选项。 *** 作完以后,就成功了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)