Prev Previous Post   Next Post Next
  #20   Report Post  
Posted to microsoft.public.excel.misc
Rowan Drummond
 
Posts: n/a
Default 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




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
checking that cells have a value before the workbook will close kcdonaldson Excel Worksheet Functions 8 December 5th 05 04:57 PM
Help with using range names in sum function soteman2005 Excel Worksheet Functions 2 November 28th 05 04:43 PM
function problem regarding cell range chindo Excel Worksheet Functions 1 November 10th 05 03:06 AM
Array to named range conversion... i-Zapp Excel Discussion (Misc queries) 4 October 25th 05 09:09 PM
Problem with an "if" relating to a range Anthony Excel Worksheet Functions 7 July 10th 05 05:46 AM


All times are GMT +1. The time now is 12:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"