Hello all,
I tried searching through the forums and didn't see the exact issue I have so here goes.
I have some data that on a monthly basis gets copied to another workbook and saved. I am trying to automate the process of doing the data copy, file saving and page formatting.
So far I have written the code that copies the data over, saves the file and part of the page formatting. The data is for a 4 month interval with 7 columns of data for each month. The issue I have is that the number of rows can vary from month to month causing data to continue to a second page. I specified a page header and I want the column names to repeat on any additional pages. The goal is to have each month have its data on separate pages in landscape. The data will always be 4 pages wide and X pages long.
Problem 1: I have placed the vertical page breaks where needed to separate the months, but I don't know how to easily determine the number of pages in length or set the print area based on the maximum row used for any month.
Problem 2: Is there a way to prevent the page header and column headers from repeating on pages that don't have any data. I set the pages tall = 20 to handle a large amount of data, but I end up with blank pages with nothing but the header information. If I set the number smaller, then the data is too small to read.
Here is the code I have so far for the page formatting
Any help is welcome (nudges Skip )
Thanks
Darvistor
I tried searching through the forums and didn't see the exact issue I have so here goes.
I have some data that on a monthly basis gets copied to another workbook and saved. I am trying to automate the process of doing the data copy, file saving and page formatting.
So far I have written the code that copies the data over, saves the file and part of the page formatting. The data is for a 4 month interval with 7 columns of data for each month. The issue I have is that the number of rows can vary from month to month causing data to continue to a second page. I specified a page header and I want the column names to repeat on any additional pages. The goal is to have each month have its data on separate pages in landscape. The data will always be 4 pages wide and X pages long.
Problem 1: I have placed the vertical page breaks where needed to separate the months, but I don't know how to easily determine the number of pages in length or set the print area based on the maximum row used for any month.
Problem 2: Is there a way to prevent the page header and column headers from repeating on pages that don't have any data. I set the pages tall = 20 to handle a large amount of data, but I end up with blank pages with nothing but the header information. If I set the number smaller, then the data is too small to read.
Here is the code I have so far for the page formatting
Code:
With Sheets("Sheet1").PageSetup
.PrintTitleRows = "$1:$3"
.PrintTitleColumns = ""
End With
Sheets("Sheet1").PageSetup.PrintArea = ""
With Sheets("Sheet1").PageSetup
.LeftHeader = ""
.CenterHeader = "&""Arial,Bold""&18" & CStr(cmonth + " " + "fname")
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = "Page &P of &N"
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 4
.FitToPagesTall = 20
.PrintErrors = xlPrintErrorsDisplayed
End With
ActiveWindow.View = xlPageBreakPreview
ActiveSheet.ResetAllPageBreaks
Set ActiveSheet.VPageBreaks(1).Location = Range("H1")
Set ActiveSheet.VPageBreaks(2).Location = Range("O1")
Set ActiveSheet.VPageBreaks(3).Location = Range("V1")
Any help is welcome (nudges Skip )
Thanks
Darvistor