|
Sub limonet()
Dim i%, j%
For i = 3 To 999
If Cells(i, "A") <> Cells(i - 1, "A") And Cells(i - 1, "A") <> "合计" And Cells(i - 1, "A") <> "客户名称" Then
Rows(i).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Cells(i, "A") = "合计"
Range(Cells(i, "D"), Cells(i, "I")).FormulaR1C1 = "=SUM(R[-" & j & "]C:R[-1]C)"
j = 0
ElseIf Cells(i, "A") = "" Then
Cells(i, "A") = "总计"
Range(Cells(i, "D"), Cells(i, "I")).FormulaR1C1 = "=SUMif(R[-" & i - 3 & "]C1:R[-1]C1,""合计"",R[-18]C:R[-1]C)"
Exit Sub
Else
j = j + 1
End If
Next i
End Sub |
|