Sub 分页()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Set ws = ThisWorkbook.Sheets("Sheet1") ' 将 "Sheet1" 替换为你的工作表名称
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row ' 获取列 A 中最后一行的行号
' 删除所有现有的分页符,避免重复插入
ws.ResetAllPageBreaks
' 从第3行开始遍历,检测班级号变化并插入分页符
For i = 3 To lastRow
If ws.Cells(i, 1).Value <> ws.Cells(i - 1, 1).Value Then
ws.HPageBreaks.Add Before:=ws.Cells(i, 1)
End If
Next i
' 插入分页符后,提醒
MsgBox "分页完成"
End Sub
记录一下分页的方法
于 2024-09-18 16:13:57 首次发布