是不是这个意思
Sub a()
Application.ScreenUpdating = False
arra = Range("a4:a" & Range("a65536").End(xlUp).Row)
Dim arrb(1 To 10000, 1 To 1)
j = 1
arrb(1, 1) = 3 '标题行 4行为数据
For i = 1 To UBound(arra)
If arra(i, 1) = "合 计" Then '找合计所在行
j = j + 1
arrb(j, 1) = i + 3
End If
Next i
For ii = j To 2 Step -1 '循环合计次数的行
r = arrb(ii, 1) - arrb(ii - 1, 1) '合计行这间有相差多少行
If r Mod 30 > 0 Then
pa = Int(r / 30) + 1 '计算有几页
Else
pa = Int(r / 30)
End If
ins = pa * 30 - r '计算插入多少行
For jj = pa To 1 Step -1 '循环页
If jj = pa Then
Rows(arrb(ii, 1) & ":" & arrb(ii, 1) + ins - 1).Insert
Rows(arrb(ii, 1) + ins + 1).Insert
Cells(arrb(ii, 1) + ins + 1, 8) = "第" & jj & "页, 共" & pa & "页"
Else
Rows(arrb(ii - 1, 1) + jj * 30 + 1).Insert
Cells(arrb(ii - 1, 1) + jj * 30 + 1, 8) = "第" & jj & "页, 共" & pa & "页"
End If
Next jj
Next ii
Application.ScreenUpdating = True
End Sub