Page Break code Not working

abeed

Board Regular
Joined
Nov 19, 2005
Messages
79
Hi:I am trying to finalize a report. In a single excel sheet, I have 6 data sets from 6 tables. I want to put only 2 table data per page. Say after 2 data set, I will give a page break at row no3 after the last data cell in that data area. Each data set has a word "ami" in header line(That I can search). How ca I give a page break. the code has some errors.
--------
sub mysub()
ActiveSheet.ResetAllPageBreaks
Columns("A:A").Select
rend = Cells(Rows.Count, "A").End(xlUp).Row

For i = 1 To rend
Set fndrng = Selection.Find(what:="ami", After:=ActiveCell)
If Not fndrng Is Nothing Then
j = j + 1
Cells(fndrng.Row, 1).Activate
r = ActiveCell.End(xlDown).Row
i = r
If (j = 2) Then
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Cells(r + 3, 1)
j = 0
End If
Else
Exit Sub
End If
Next i
End Sub

--Where is the error and howw can I simplify the code? I know its not efficient.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
abeed said:
Hi:I am trying to finalize a report. In a single excel sheet, I have 6 data sets from 6 tables. I want to put only 2 table data per page. Say after 2 data set, I will give a page break at row no3 after the last data cell in that data area. Each data set has a word "ami" in header line(That I can search). How ca I give a page break. the code has some errors.
--------

Have you checked Page Setup to see if you have Page, Scaling, Fit to selected rather than Scaling, Adjust to, if so excel ignores any Page Break settings.
 
Upvote 0

Forum statistics

Threads
1,214,838
Messages
6,121,885
Members
449,057
Latest member
Moo4247

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