Home |
Search |
Today's Posts |
#20
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Try something like:
Sub PgBreaks() Dim fndCell As Range Dim pb As Long Dim firstAddress As String With ActiveSheet.Cells Set fndCell = .Find(what:="J/J", After:=Range("A1"), _ LookIn:=xlValues, LookAt:=xlPart, _ SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False) If Not fndCell Is Nothing Then firstAddress = fndCell.Address Do If pb = 2 Then ActiveSheet.HPageBreaks.Add Befo=fndCell pb = 1 Else pb = pb + 1 End If Set fndCell = .FindNext(fndCell) Loop While Not fndCell Is Nothing _ And fndCell.Address < firstAddress End If End With End Sub Hope this helps Rowan jesmin wrote: Hi Rowan: Thanks for everything. I will not touch the code any more as it is creating my report. Thanks all your help and your patience. Now I am trying to finalize it this way. I want to put only 2 reports per page. Say after 2 reports, I will give a page break at line number 40. I know that 2 reports will take maximum 4o lines(including heading etc). Each report has a word "J/J" in header line(That I can search). So in each page I will have 2 headers with text "J/J". I was thinking to code this way: ------------------------------------ dim i as Integer dim fnd as Boolean dim fndrng as Range Set fndrng = activesheet.usedrange.find(what:="J/J") do while(fnd=true) i=i+1 if (i=2) then activesheet.pagebreak.rows=40 i=0 end if set activesheet.usedrange.findNext(what:="J/J")---I dont know exact code. end loop --I know the above approach is not well enough. I would request you a better idea. Thanks again |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
checking that cells have a value before the workbook will close | Excel Worksheet Functions | |||
Help with using range names in sum function | Excel Worksheet Functions | |||
function problem regarding cell range | Excel Worksheet Functions | |||
Array to named range conversion... | Excel Discussion (Misc queries) | |||
Problem with an "if" relating to a range | Excel Worksheet Functions |