coditional Page Break

J

j4m3sc

Hi

I have a problem where i need to use automated page breaks on excel.

I'd like a page break each time the word "accounting" appears in Column A.
To make my problem even harder for me is that there are blank cells in
Column A.

I know VGA code will be needed but cannot do this myself.

Please help
 
G

Gord Dibben

Sub Insert_PBreak_Col()
Dim rng As Range
Dim Cell As Range
Set rng = Intersect(ActiveSheet.UsedRange, Columns(1))
For Each Cell In rng
If Cell.Text = "accounting" Then
Cell.Offset(1, 1).PageBreak = xlPageBreakManual
End If
Next
End Sub

Will insert a pagebreak below the word "accounting"

If you want it above, change the line

Cell.Offset(1, 1).PageBreak = xlPageBreakManual to

Cell.PageBreak = xlPageBreakManual


Gord Dibben MS Excel MVP
 
A

Ashish Mathur

Hi,

A non macro approach would be using the Data > Subtotal feature. First of
all sort column A. Then highlight the range and navigate to Data >
Subtotal. Provide the relevant inputs and check the box for "Create page
breaks"

Hope this helps.

--
Regards,

Ashish Mathur
Microsoft Excel MVP
www.ashishmathur.com
 

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