|
Sub 插入分类小计()
Sheets("分类统计").Activate
If Cells(Rows.Count, 2).End(3) = "小计" Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim r&, k&, m&, n&
m = 3: n = 3
Do While Cells(m, 1) <> ""
k = k + 1
If Cells(m, 1) <> Cells(m + 1, 1) Then
m = m + 1
Cells(m, 1).Resize(1, 4).Insert Shift:=xlDown
Cells(m, 2) = "小计"
Cells(m, 3) = "=SUBTOTAL(109,R[" & -k & "]C:R[-1]C)"
Cells(m, 4) = "=SUBTOTAL(109,R[" & -k & "]C:R[-1]C)"
Cells(n, 1).Resize(k + 1, 1).Merge
n = n + k + 1: k = 0
End If
m = m + 1
Loop
[a1].CurrentRegion.Borders.LineStyle = 1
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub |
|