Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Find page breaks in excel

24 views
Skip to first unread message

Josh

unread,
Sep 9, 2002, 4:52:48 PM9/9/02
to
I am trying to use VBA to automatically make and index out
of an excel documents. I need to find the row number of
all page breaks. Please help!! thanks

Josh

Tom Ogilvy

unread,
Sep 9, 2002, 6:52:38 PM9/9/02
to
Here is some code I provided someone else working with pagebreaks. You can
probably adapt it for your purpose:

May answer to Stuart.
-----------------
As an example, this colors column A between each pagebreak. It uses a
random color, so there is the possibility of having the same color twice in
succession.

Sub Tester1aa()
Dim HPBCell() As Range
Dim Cell As Range
Dim AR As Range
Dim HPBreak As HPageBreak
Dim icolor As Integer
Dim i As Long
ReDim HPBCell(1 To 2)
Set HPBCell(1) = Range("A1")
If ActiveSheet.HPageBreaks.Count > 0 Then
For i = 1 To ActiveSheet.HPageBreaks.Count
Set HPBreak = ActiveSheet.HPageBreaks(i)
If HPBreak.Type = xlPageBreakAutomatic Then

Set HPBCell(UBound(HPBCell, 1)) = HPBreak.Location
ReDim Preserve HPBCell(1 To UBound(HPBCell, 1) + 1)
End If
Next
End If
Set HPBCell(UBound(HPBCell)) = _
Cells(Rows.Count, 1).End(xlUp)(2)
Randomize
i = 0
If UBound(HPBCell, 1) > 2 Then
For i = 1 To UBound(HPBCell, 1) - 1
icolor = Int(Rnd() * 56 + 1)
For Each Cell In Range(HPBCell(i), HPBCell(i + 1).Offset(-1, 0))
Cell.Interior.ColorIndex = icolor
Next
Next
End If
End Sub

----------< end of post>----

Regards,
Tom Ogilvy


Josh <Jha...@hotmail.com> wrote in message
news:9b9301c25842$dac9a890$9de62ecf@tkmsftngxs01...

0 new messages