Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Inserting page break conditionally

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 Befo=Cells(i,
1)
End If
Next

Application.ScreenUpdating = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Inserting page break conditionally

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.

"RITCHI" wrote:

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 Befo=Cells(i,
1)
End If
Next

Application.ScreenUpdating = True
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Inserting page break conditionally

P.S. The ActiveSheet.Activate command is ambiguous since the sheet would
already be active.

"RITCHI" wrote:

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 Befo=Cells(i,
1)
End If
Next

Application.ScreenUpdating = True
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Inserting page break conditionally

On Sep 30, 8:12 pm, JLGWhiz wrote:
P.S. The ActiveSheet.Activate command is ambiguous since the sheet would
already be active.



"RITCHI" wrote:
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 Befo=Cells(i,
1)
End If
Next


Application.ScreenUpdating = True
End Sub- Hide quoted text -


- 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.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Inserting page break conditionally

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.

"RITCHI" wrote:

On Sep 30, 8:12 pm, JLGWhiz wrote:
P.S. The ActiveSheet.Activate command is ambiguous since the sheet would
already be active.



"RITCHI" wrote:
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 Befo=Cells(i,
1)
End If
Next


Application.ScreenUpdating = True
End Sub- Hide quoted text -


- 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.


Reply
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
Inserting page break da Excel Discussion (Misc queries) 3 May 29th 09 10:37 PM
VBA From MS Access: Inserting Page Break? PeteCresswell Excel Programming 8 December 6th 06 02:00 AM
Inserting A row & page break Jamie Excel Programming 1 June 13th 06 06:09 PM
Inserting header @ page break Esrei Excel Discussion (Misc queries) 1 August 12th 05 01:36 PM
Inserting rows before page break Robert Christie[_3_] Excel Programming 5 December 15th 03 05:24 AM


All times are GMT +1. The time now is 11:48 AM.

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

About Us

"It's about Microsoft Excel"