Sweetmusic1
New Member
- Joined
- Dec 1, 2014
- Messages
- 6
I am unable to figure out how to write the VBA code to ignore page breaks if certain rows are hidden / allow page breaks if rows are not hidden. I am new to VBA code writing. I have checkboxes that when selected the rows will hide or expand when checked. I have the following print command that contains hard page breaks but if a certain selection is hidden the page break still stays. I would appreciate any help in writing this to work properly.
[Range("A7:N146").Select
ActiveSheet.PageSetup.PrintArea = "$A$7:$N$146"
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Worksheets(1).Range("a27")
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Worksheets(1).Range("a43")
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Worksheets(1).Range("a63")
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Worksheets(1).Range("a91")
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Worksheets(1).Range("a118")
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Worksheets(1).Range("a139")
If Not ActiveWindow.ActiveSheet.Range("a7:a26").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a27")
End If
If Not ActiveWindow.ActiveSheet.Range("a27:a42").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a43")
End If
If Not ActiveWindow.ActiveSheet.Range("a43:a62").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a63")
End If
If Not ActiveWindow.ActiveSheet.Range("a63:a90").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a91")
End If
If Not ActiveWindow.ActiveSheet.Range("a91:a117").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a118")
End If
If Not ActiveWindow.ActiveSheet.Range("a118:a138").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a139")
End If
If Not ActiveWindow.ActiveSheet.Range("a139:a146").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a147")
End If
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:="pdfFactory Pro", Collate:=True, _
IgnorePrintAreas:=False
End Sub
[Range("A7:N146").Select
ActiveSheet.PageSetup.PrintArea = "$A$7:$N$146"
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Worksheets(1).Range("a27")
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Worksheets(1).Range("a43")
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Worksheets(1).Range("a63")
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Worksheets(1).Range("a91")
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Worksheets(1).Range("a118")
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Worksheets(1).Range("a139")
If Not ActiveWindow.ActiveSheet.Range("a7:a26").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a27")
End If
If Not ActiveWindow.ActiveSheet.Range("a27:a42").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a43")
End If
If Not ActiveWindow.ActiveSheet.Range("a43:a62").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a63")
End If
If Not ActiveWindow.ActiveSheet.Range("a63:a90").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a91")
End If
If Not ActiveWindow.ActiveSheet.Range("a91:a117").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a118")
End If
If Not ActiveWindow.ActiveSheet.Range("a118:a138").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a139")
End If
If Not ActiveWindow.ActiveSheet.Range("a139:a146").Hidden Then
ActiveSheet.HPageBreaks.Add Before:=Worksheets(1).Range("a147")
End If
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:="pdfFactory Pro", Collate:=True, _
IgnorePrintAreas:=False
End Sub