Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Inserting page break conditionally

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RITCHI - 30 Sep 2007 17:41 GMT
Hi

I want to insert a page break before a cell if the cell value meets
certain conditions.
I've tried the code below which seemd to work some of the time ut not
consistently.

Sub InsertPageBreaks()

   Application.ScreenUpdating = False
   ActiveSheet.Activate
   'ActiveSheet.ResetAllPageBreaks

   lr = Cells(Rows.Count, 1).End(xlUp).Row
   For i = lr To 6 Step -1
       If InStr(Cells(i, 1).Value, "---") > 0 Then
       ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Cells(i,
1)
       End If
   Next

   Application.ScreenUpdating = True
End Sub
JLGWhiz - 30 Sep 2007 20:09 GMT
Have you checked the InStr value when it does not work to see if it equates
to false.  That is, it does not find the "---" criteria.

> Hi
>
[quoted text clipped - 19 lines]
>     Application.ScreenUpdating = True
> End Sub
JLGWhiz - 30 Sep 2007 20:12 GMT
P.S.  The ActiveSheet.Activate command is ambiguous since the sheet would
already be active.

> Hi
>
[quoted text clipped - 19 lines]
>     Application.ScreenUpdating = True
> End Sub
RITCHI - 30 Sep 2007 20:45 GMT
> P.S.  The ActiveSheet.Activate command is ambiguous since the sheet would
> already be active.
[quoted text clipped - 24 lines]
>
> - Show quoted text -

Thanks JLGWhiz

Although I've not solved it completely the problem is related to the
Page Setup being configured for Fit to x by y pages.
Once I remove one of the fit to conditions it works, and interestingly
the page breaks are visible again in the normal view.
When the page set up includes a fit to X by y pages even though I
insert a page break manually you can't see it, but it exists.
JLGWhiz - 30 Sep 2007 23:43 GMT
I believe the Fit To... pages overrides any manual page breaks.  It does its
own calculation of where the page breaks go to meet the Fit To criteria.

> > P.S.  The ActiveSheet.Activate command is ambiguous since the sheet would
> > already be active.
[quoted text clipped - 33 lines]
> When the page set up includes a fit to X by y pages even though I
> insert a page break manually you can't see it, but it exists.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.