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
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

QuietRiot

Well-known Member
Joined
May 18, 2007
Messages
1,077
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
 

QuietRiot

Well-known Member
Joined
May 18, 2007
Messages
1,077
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,258
Messages
5,600,567
Members
414,389
Latest member
MarkElla

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
Top