ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Coding for Page Break (https://www.excelbanter.com/excel-discussion-misc-queries/60928-coding-page-break.html)

jesmin

Coding for Page Break
 

Hi TheI am generating an excel report. In a single excel sheet, I
have 6 data sets from 6 tables. I want to put only 2 data sets per
page. After this 2 data set, I need a page break at row no3 after the
last data cell in that data area(2nd set data). Each data set has a
common word "J/J" in top line. this I will find(). How ca I give a page
break. I tried this code but not working.
--------
sub pgbreak()
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 Befo=Cells(r + 3, 1)
j = 0
End If
Else
Exit Sub
End If
Next i
End Sub

I am getting an error looping several times. How can I simplify the
code?

Thanks in advance.


--
jesmin
------------------------------------------------------------------------
jesmin's Profile: http://www.excelforum.com/member.php...o&userid=29540
View this thread: http://www.excelforum.com/showthread...hreadid=494411



All times are GMT +1. The time now is 12:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com