INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

E-mail*
Handle

Password
Verify P'word
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Member Feedback

"...You have made an incredible site which is truly a great help to me in solving problems. A tip of my hat to you!..."

Geography

Where in the world do Tek-Tips members come from?
SkipVought (Programmer)
31 Jan 08 14:56
An Inelegant Excel PageBreak Solution

I have an Excel report:
row 1 headings (23 columns)
Variable row depth
rows logically grouped on Column A value.

Print requirement:
ONE page wide
page break ONLY when Column A value changes but not on EVERY column A value change.

Column A PageBreak Example:

BEFORE:

a
a
a
b
b
b
b
c
c_ _ _ _ _ _ _ _ _ Auto Page Break
d
d
d
d
d

AFTER:

a
a
a
b
b
b
b_________________ MANUAL Page Break
c
c
d
d
d
d
d

What I have discovered is that when the PageSetup.Zoom property is assigned FALSE, along with the FitToPagesWid=1 and FitToPagesTall=999, then the HPageBreaks.Add method does NOTHING.

So after fiddling with this for over a week, and getting some helpful advise from xlbo, I stumbled upon this inelegant solution.  Can anyone find a better way?

CODE

Sub PageSetupZoom()
    Dim nZoom As Integer
'assign the MAXIMUM zoom value
    nZoom = 400
    With ActiveSheet
        .ResetAllPageBreaks
        Do
            .PageSetup.Zoom = nZoom
'toggling between NORMAL & PAGE BREAK PREVIEW is the only way I could get the darn setup to actually change!!!
            ActiveWindow.View = xlNormalView
            ActiveWindow.View = xlPageBreakPreview
'decriment the zoom value
            nZoom = nZoom - 5
'when there are NO VPageBreak objects, that's when I have a page that is 1 wide AND ZOOM is not FALSE!!!
        Loop While .VPageBreaks.Count > 0
    End With
    ReformatPageBreaks ActiveSheet, ActiveSheet.[A1]
End Sub
Having setup my page for printing, now I can reformat the HPageBreaks, which appears ONLY TO WORK when the PageSetup.Zoom property is not FALSE...

CODE

Sub ReformatPageBreaks(ws As Worksheet, rg As Range)
    Dim lRow As Long, i As Integer, iCol As Integer
    iCol = rg.Column
    With ws
'        .ResetAllPageBreaks
        Do
            'next page break
            lRow = .HPageBreaks(i).Location.Row
            Do While .Cells(lRow, iCol).Value = .Cells(lRow - 1, iCol).Value
                lRow = lRow - 1
            Loop
            .HPageBreaks.Add .Cells(lRow, iCol)
            
            i = i + 1
        Loop Until .HPageBreaks.Count < i
    End With
End Sub
What say ye?

Skip,

glassesDid you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty!tongue

Tek-Tips Forums is Member Supported. Click Here to donate.
SkipVought (Programmer)
31 Jan 08 16:59



I just noticed a line of code that I inadvertently deleted...

CODE

Sub ReformatPageBreaks(ws As Worksheet, rg As Range)
    Dim lRow As Long, i As Integer, iCol As Integer
    iCol = rg.Column
    With ws
        i = 1

        Do
            'next page break
            lRow = .HPageBreaks(i).Location.Row
            Do While .Cells(lRow, iCol).Value = .Cells(lRow - 1, iCol).Value
                lRow = lRow - 1
            Loop
            .HPageBreaks.Add .Cells(lRow, iCol)
            
            i = i + 1
        Loop Until .HPageBreaks.Count < i
    End With
End Sub

Skip,

glassesDid you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty!tongue

Helpful Member!combo (TechnicalUser)
1 Feb 08 11:56
I wouldn't bother scalling:

CODE

ws.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1

combo

SkipVought (Programmer)
1 Feb 08 12:50



Elegant!!!

First time I have ever been "in drag!"

One statement replaces all that crap!

What's interesting is that I could have MULTIPLE VPageBreaks, but dragging off the FIRST ONE, removes ALL.

Hat's off to you, and have a great Super Bowl weekend!

Ain't Tek-Tips WONDERFUL!!!

Skip,

glassesDid you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty!tongue

SkipVought (Programmer)
1 Feb 08 12:59



Quote (ME):

What's interesting is that I could have MULTIPLE VPageBreaks, but dragging off the FIRST ONE, removes ALL.
DUH! Makes PERFECT sense.  VPageBreak at the RIGHTMOST print area, means...

no more VPageBreaks!!!

Again, great tip combo!!!

Skip,

glassesDid you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty!tongue

Helpful Member!combo (TechnicalUser)
1 Feb 08 13:11
Thanks Skip! The macro recorder was really nice tool this timelol...
Have a nice weekend toocheers.

combo

Start A New Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Promoting, selling, recruiting and student posting
are not allowed in the forums.
Posting Policies

LINK TO THIS FORUM!
(Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum)
TITLE: VBA Visual Basic for Applications (Microsoft) Forum at Tek-Tips
URL: http://www.tek-tips.com/threadminder.cfm?pid=707
DESCRIPTION: VBA Visual Basic for Applications (Microsoft) technical support forum and mutual help system for computer professionals. Selling and recruiting forbidden.