支气管扩张咯血的饮食:请教VBA高手

来源:百度文库 编辑:神马品牌网 时间:2024/05/05 12:09:02
以下是一个VBA作品用于EXCEL,做到每页小计,最后合计,请问错在哪里如何修正!万分感激!!!
Sub 分页小计()

Dim i, t, l, x, rr, dr, tt As Integer
Dim rrr As String
Public Sub Fyhz()
t = 2
Do
i = InputBox("请输入每页拟打印的行数: (不能超过一页的范围!!!)")

If i <= 0 Or i = "" Then
MsgBox ("每页行数必须大于1!")
Else
Exit Do
End If
Loop
i = Int(i)
x = i + 1
l = Range("A65536").End(xlUp).Row
Do While l >= x

Rows(x + 1).Insert Shift:=xlDown
Cells(x + 1, 1) = "本页小计"
Cells(x + 1, 2).Formula = "=SUM(R[-" + CStr(i) + "]C:R[-1]C)"
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Rows(x + 2)
x = (i + 1) * t
t = t + 1
l = l + 1
Loop

If l Mod (i + 1) <> 1 Then
rr = l Mod (i + 1)
rr = rr - 1
rrr = CStr(rr)
Cells(l + 1, 1) = "本页小计"
Cells(l + 1, 2).FormulaR1C1 = "=SUM(R[-" + rrr + "]C:R[-1]C)"
End If
Cells(l + 2, 1) = "合计"
Cells(l + 2, 2).FormulaR1C1 = "=SUM(R[-" + CStr(l + 1) + "]C:R[-1]C)/2"
Range(Cells(1, 1), Cells(l + 1, 2)).Locked = True
ActiveSheet.Protect
Cells(1, 1).Select
End Sub