Sub demo()
Application.DisplayAlerts = False
ae = Range("a2:e" & Cells(Rows.Count, 1).End(xlUp).Row)
r = 1: p = 0
For i = 1 To UBound(ae)
Sum = Sum + ae(i, 4)
Do While j + 30 <= Sum
j = j + 30
r = r + 1: If j - p = 30 Then n = n + 1
Cells(r, "h").Value = ae(i, 1)
Cells(r, "i").Value = n
Cells(r, "j").Value = j - p
Cells(r, "k").Value = ae(i, 4)
sum2 = sum2 + j - p: p = j
Loop
If j < Sum Then
r = r + 1: If sum2 Mod 30 = 0 Then n = n + 1
Cells(r, "h").Value = ae(i, 1)
Cells(r, "i").Value = n
Cells(r, "j").Value = Sum - p
Cells(r, "k").Value = ae(i, 4)
sum2 = sum2 + Sum - p: p = Sum
End If
Next
For i = r To 2 Step -1
If Cells(i, "i") = Cells(i - 1, "i") Then Range(Cells(i - 1, "i"), Cells(i, "i")).Merge
If Cells(i, "k") = Cells(i - 1, "k") Then Range(Cells(i - 1, "k"), Cells(i, "k")).Merge
Next
End Sub
祝順心,南無阿彌陀佛!