Range Problem
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
|