|
- Sub 插入合计行()
- Dim K%, S%
- K = 5: S = 5
- Application.ScreenUpdating = False '关闭刷新 提高速度
- Do
- If CDate(Cells(K, 1)) <> CDate(Cells(K + 1, 1)) Then '合计项
- Rows(K + 1 & ":" & K + 2).Insert '插入2行
- Cells(K + 1, 3) = "本日合计"
- Range(Cells(K + 1, 4), Cells(K + 1, 5)) = "=sum(r" & S & "c:r[-1]c)"
- Cells(K + 2, 3) = "累计合计"
- Range(Cells(K + 2, 4), Cells(K + 2, 5)) = "=sumif(r4c3:r[-1]c3, ""本日合计"",r4c:r[-1]c)+r4c"
- Range(Cells(K + 1, 3), Cells(K + 2, 5)).Interior.ColorIndex = 40 '填充底色
- Cells(K + 1, 2).Resize(2, 4).Font.Bold = True '加粗字体 (Resize 扩大区域) 返回区域与上句一样
- K = K + 2: S = K + 1
- End If
- K = K + 1
- Loop Until Cells(S, 2) = ""
- Range("A4").Resize(K - 4, 7).Borders.LineStyle = 1 '加网格线
- Application.ScreenUpdating = True '开启刷新
- MsgBox "完成"
- End Sub
复制代码 |
|