Page Break Macro

csshot2

New Member
Joined
Jun 17, 2004
Messages
15
Not very good at VBA and have found this board useful in the past…any help would be greatly appreciated.

I need a macro that will review the cells in column A and every time it finds 81??? it will insert a page break. For example (see below), it will stop at 81016 and insert a page break, then it will proceed down to 81020 and insert another page break, and so on.

Column A
81016
USDA CSREES
AG-Fed Smith Lev
2358236000
81020
USDA CSREES
AG-Fed Smith Lev
2350206000
81030
USDA CSREES
AG-Fed Smith Lev
2350016000
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Code:
Sub Macro1()
   
   Last = Range("A65536").End(xlUp).Row

    For x = 1 To Last
    If Left(Cells(x, 1).Value, 2) = "81" Then
        ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Cells(x + 1, 1)
    End If
    Next
    
End Sub
 
Upvote 0
oh i wasn't clear on wheter you wanted it before or after the 81#

right now its after if you want it before just change: Before:= Cells(x,1) instead of x+1
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,630
Members
449,041
Latest member
Postman24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top