发布网友 发布时间:2022-04-21 16:46
共1个回答
热心网友 时间:2023-09-17 09:39
Sub 小计求和()
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