Hi cri
Just a shot in the dark........ Have you tried a DoEvent in the loop after each time the page break is set ???
Peter
Main Topics
Browse All TopicsHi,
In a large application I am finalizing, I have trouble to get my page setup right.
The report, which is an Excel worksheet based on a template, is created on the fly at the end of my code.
When the report is finalized, I need to specify which pages need to be inside the 'Print Area', but I also want to adjust the Page Breaks.
Manual or forced page breaks are already partially preset in the template, but on some pages, the tables vary in length. I don't want a table to be split up in the middle of it, so I have used a method which finds me the start of the table and sets the page break by force on my preferred place.
The only problem is, that I have to rely on the automatic page breaks which Excel should fix after the report sheet is created and there lies my problem.
If I run the 'Manual Page Break' part of the macro, after the code has finalized, it works fine.
But, when inside the loop, it seems that Excel does not have the speed to calculate the page breaks, as they simply don't appear fast enough, which makes my code fail.
The question is, if anyone out here has experienced this type of behaviour, and obviously, if that particular person found a remedy for it.
I have tried to play with
Application.ScreenUpdating
Application.Calculation = xlCalculationManual 'or xlCalculationAutomatic
in all sort of ways, and by doing
Application.Calculate
prior to the page break part of the macro at no avail.
As an example, the line below is used to determine the total numbers of page to be printed, but does not work, for the same reason as explained above
qteSheet.PageSetup.RightFo
May your thought be inspired ...
calacuccia
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hello everyone.
If no response to the comments below, I will delete this question and return the points to calacuccia.
We are cleaning up this topic area. This question is considered to be *outdated* and we would like you to move on with it.
Toward that end, we graciously request the following:
-----Askers-----
*Do NOT award points to moderators (me).
*Stay active in your question. Please respond to all experts' comments immediately.
*Do one of the following, please:
--Award points to an expert for good answer or good effort.
--Post that you'd like to withdraw the question (the DELETE button does NOT work).
--Ask experts for more help.
Thanks very much for being fair to our experts.
-----Experts-----
*Do NOT provide further support to this question unless asked by the Asker.
*Post your opinion on who should receive points, even if it is you, or the question may be unnecessarily deleted.
*Don't thank the moderator for granting points to you, this only causes more email for everyone (but thanks for the thought!).
Finally, if anyone does not like the moderator's determination, say so immediately and suggest your own.
Your input is extremely valuable and very much appreciated.
thank you!
amp
community support moderator
amp@experts-exchange.com
Hi cal,
You can either see the whole discussion: http://www.experts-exchang
or, the bulk of the code was:
The following code will insert a subtotal at the bottom of each page, a blank row and a carried forward
subtotal on each subsequent page, and a grand total two cells below the final value in column B. After
completing the print, it will also delete the inserted rows. This code will run if your data is set
out as you previously provided i.e. Column A contains customer details, Column B contains Numeric data
for totalling.
If yoru sheet name is not Sheet1, then you will need to change those references in the code below.
It runs at around 3-4 seconds a page on my 400. There are no doubt quicker ways to do this, however
this method is functional.
Sorry took a while to get back to you - have a lot on at present, and probably bit off more than I should
have.
Sub PrintSubTotals()
' Init looping variable
Counter = 1
Application.ScreenUpdating
' Refresh page breaks and clear print areas
ActiveSheet.ResetAllPageBr
ActiveSheet.PageSetup.Prin
' Loop for processing
While Worksheets("Sheet1").Cells
' Test if the current row + 1 has page break marker and next row in
' column B is not empty
If Worksheets("Sheet1").Rows(
Range("B" & Counter + 1).Value > 0 Then
' Select rows 1 either before and two after break, and insert three new rows
Rows((Counter + 1) & ":" & (Counter + 3)).Select
Selection.Insert Shift:=xlDown
' Show "Sub Total" in bottom of column A
Cells(Counter + 1, 1).Select
Cells(Counter + 1, 1).Value = "Sub Total"
Selection.Font.Bold = True
' Set value to Sum This Page in column B
Cells(Counter + 1, 2).Select
ActiveCell.FormulaR1C1 = "=Sum(R[" & CStr(-Counter) & "]C2:R[-1]C2)"
' Format the SubTotal and CF cells
Range("B" & Counter + 1).Select
Selection.Font.Bold = True
With Selection.Borders(xlEdgeTo
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBo
.LineStyle = xlContinuous
.Weight = xlThin
End With
Range("B" & Counter + 3).Select
Selection.Font.Bold = True
With Selection.Borders(xlEdgeTo
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBo
.LineStyle = xlContinuous
.Weight = xlThin
End With
' Show "Carried Forward" in Column A
Cells(Counter + 3, 1).Select
Cells(Counter + 3, 1).Value = "Carry Fwd."
Selection.Font.Bold = True
' Set carry forward formula
Cells(Counter + 3, 2).Select
ActiveCell.FormulaR1C1 = "=(R[-2]C)"
' Refresh Page Breaks
ActiveSheet.ResetAllPageBr
ActiveSheet.PageSetup.Prin
' Increment counter to skip the inserted blank row
Counter = Counter + 1
' Keep track of position of last subtotal for Grand Total
LastSub = Counter
End If
' Inc counter for next in loop
Counter = Counter + 1
Wend
' Select next empty cell in B, and insert Grand Total amount
Range("B" & Counter + 2).Select
ActiveCell.FormulaR1C1 = "=Sum(R[" & CStr(-(Counter - LastSub)) & _
"]C2:R[-1]C2)"
' Format Grand Total cell
Selection.Borders(xlDiagon
Selection.Borders(xlDiagon
With Selection.Borders(xlEdgeLe
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTo
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBo
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRi
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
' Provide text and format
Cells(Counter + 2, 1).Value = "Grand Total"
Range("A" & (Counter + 2) & ":B" & Counter + 2).Select
Selection.Font.Bold = True
'ActiveWindow.SelectedShee
' Processing loop to remove inserted rows
For DeleteCounter = 1 To Counter
If Range("A" & (DeleteCounter + 1)).Value = "Sub Total" Or _
Range("A" & (DeleteCounter + 1)).Value = "Grand Total" Then
Rows(DeleteCounter + 1 & ":" & DeleteCounter + 3).Select
Selection.Delete Shift:=xlUp
End If
Next
Application.ScreenUpdating
End Sub
There may be something of use - particularly if you can avoid relying on XL auto break points.
Also, while you are round, did you see this one:
http://www.experts-exchang
Dave
Business Accounts
Answer for Membership
by: criPosted on 2001-10-03 at 01:31:38ID: 6522465
Off the cuff, how about putting a short delay, be this a 1-2 sec timer or some input box asking for some confirmation ?