Code to insert a Page Break

M

Moore

I would like to know if it is possible to write a VB code
to insert page breaks into a spreadsheet when a value is
encountered in a column. I am using Excel 2002
 
D

Dave Peterson

I'd modify JE's code slightly to avoid A1 and maybe remove all the existing page
breaks.

Option Explicit
Sub test()

Const MYVAL As Double = 1
Dim cell As Range

ActiveSheet.ResetAllPageBreaks

For Each cell In Range("A2:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
If cell.Value = MYVAL Then _
ActiveSheet.HPageBreaks.Add Before:=cell
Next cell

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top