I've been trying to get page breaks automatically inserted based on text within a specific cell.
Most page breaks will use the text string "Project :" within the headers to insert a page break 4 rows above at the top of the page header.
The cell which contains this "Project :" is either the text string itself, or a formula whose result is this text string.
I have included a link to a sample document below, hoping someone can help me out.
I've marked on the right hand side of this document where I need the page breaks to be inserted.
Most page breaks required at the headers but for the large table, I need page breaks to be inserted so that it fits enough table rows to fill each page to minimise white space on each page.
In the original document, the entire table content is populated using formulae to pull info from a separate master worksheet, but the result in each table cell is either a text string or a numerical value.
Example Excel Test File
Below is the VBA code I currently put together using various sources, mostly from MrExcel.com
Whilst it doesn't give any runtime errors, it doesn't do what I need it to.
My VBA skills are pretty much non-existent so I am hoping some VBA wizard here will be able to help me make it work and achieve the desired outcome.
Your help with this would be very much appreciated.
Most page breaks will use the text string "Project :" within the headers to insert a page break 4 rows above at the top of the page header.
The cell which contains this "Project :" is either the text string itself, or a formula whose result is this text string.
I have included a link to a sample document below, hoping someone can help me out.
I've marked on the right hand side of this document where I need the page breaks to be inserted.
Most page breaks required at the headers but for the large table, I need page breaks to be inserted so that it fits enough table rows to fill each page to minimise white space on each page.
In the original document, the entire table content is populated using formulae to pull info from a separate master worksheet, but the result in each table cell is either a text string or a numerical value.
Example Excel Test File
Below is the VBA code I currently put together using various sources, mostly from MrExcel.com
Whilst it doesn't give any runtime errors, it doesn't do what I need it to.
My VBA skills are pretty much non-existent so I am hoping some VBA wizard here will be able to help me make it work and achieve the desired outcome.
Your help with this would be very much appreciated.
VBA Code:
Sub InsertPageBreaks()
Dim c As Range
Application.ScreenUpdating = False
ActiveWindow.View = xlNormalView
With ActiveSheet
.Unprotect Password:="password"
.ResetAllPageBreaks
.Cells.PageBreak = xlPageBreakNone
.Columns("D").Insert
.Columns("C").Copy .Columns("D")
.Columns("D").Replace "Project :", "#N/A"
On Error Resume Next
For Each c In .Columns("D").SpecialCells(2, xlErrors)
c.Offset(-4, 0).PageBreak = xlPageBreakManual
Next c
.Columns("D").Delete
.Protect Password:="password"
End With
Application.ScreenUpdating = True
'
MsgBox " PAGE BREAKS SET!!" & vbCrLf & " Press OK"
End Sub