Current Special! Complete Excel
for Excel 97 - Excel 2003, only
30 Day Money Back Guarantee & Free
Excel Help for LIFE!
Got any Excel Questions? Free Excel Help
I trying to develop a macro to print my worksheets. Here's the problem, I never know how much data my end-users will incorporate into any one worksheet. In some instances, one worksheet can result in five pages or more of printout. How do I achieve the following:
1.) set a page break so that if, for example, I have 400 rows or 4000 rows of data that each page print 40 rows data.
2.) Print multiple row column headings on each page.
I would appreciate any help on the subject.
Hans Pottel provided a VBA solution
Dim pages As Integer
Dim pageBegin As String
Dim PrArea As String
Dim i As Integer
Dim q As Integer
Dim nRows As Integer, nPagebreaks As Integer
Dim R As Range
Set R = ActiveSheet.UsedRange
'add pagebreak every 40 rows
nRows = R.Rows.Count
If nRows > 40 Then
nPagebreaks = Int(nRows / 40)
For i = 1 To nPagebreaks
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=R.Cells(40 * i + 1, 1)
'can be used in a separate macro, as I Start counting the number of pagebreaks
pages = ActiveSheet.HPageBreaks.Count
pageBegin = "$A$1"
For i = 1 To pages
If i > 1 Then pageBegin = ActiveSheet.HPageBreaks(i - 1).Location.Address
q = ActiveSheet.HPageBreaks(i).Location.Row - 1
PrArea = pageBegin & ":" & "$H$" & Trim$(Str$(q))
ActiveSheet.PageSetup.PrintArea = PrArea
' the cell in column 1 and in the row immediately below the pagebreak
' contains text for the footer
ActiveSheet.PageSetup.CenterFooter = Cells(q, 1)
' ActiveSheet.PrintOut copies:=1
Excel Dashboard Reports & Excel Dashboard Charts 50% Off Become an ExcelUser Affiliate & Earn Money
Special! Free Choice of Complete Excel Training Course OR Excel Add-ins Collection on all purchases totaling over $64.00. ALL purchases totaling over $150.00 gets you BOTH! Purchases MUST be made via this site. Send payment proof to email@example.com 31 days after purchase date.
Instant Download and Money Back Guarantee on Most Software
Excel Trader Package Technical Analysis in Excel With $139.00 of FREE software!
Microsoft ® and Microsoft Excel ® are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft
Some of our more popular products are below...
Convert Excel Spreadsheets To Webpages | Trading In Excel | Construction Estimators | Finance Templates & Add-ins Bundle | Code-VBA | Smart-VBA | Print-VBA | Excel Data Manipulation & Analysis | Convert MS Office Applications To...... | Analyzer Excel | Downloader Excel | MSSQL Migration Toolkit | Monte Carlo Add-in | Excel Costing Templates