很简单吧,应该又很多种做法,因为不知道你的行列号,所以下面代码可以给你参考一下,我是以A1单元格为第一格写的,具体情况你按照你的表格修改一下就行了
Sub test1()
Dim RngArea As Range, arr() As Variant, brr() As Variant
Dim Rng As Range, Months As String, i As Integer, Sum As Double
Set RngArea = ActiveSheet.UsedRange.Columns(1).Cells
For Each Rng In RngArea
Sum = Rng.Offset(0, 2).Value + Sum
If Months = Empty Or Months <> Month(CDate(Rng.Value)) Then
i = i + 1
ReDim Preserve arr(1 To i)
ReDim Preserve brr(1 To i)
arr(i) = Rng.Row: brr(i) = Sum - Rng.Offset(0, 2).Value
Sum = Rng.Offset(0, 2).Value
Months = Month(CDate(Rng.Value))
End If
Next
i = i + 1: ReDim Preserve brr(1 To i): ReDim Preserve arr(1 To i)
arr(i) = ActiveSheet.UsedRange.Rows.Count + 1: brr(i) = Sum
Stop
For i = UBound(arr) To LBound(arr) + 1 Step -1
Rows(arr(i)).Insert
Cells(arr(i), 1) = ""
Cells(arr(i), 3) = brr(i)
Next
End Sub