Print macro help

ed.ayers315

Board Regular
Joined
Dec 14, 2009
Messages
166
Hi forum goes,

Need help on the following code. I pieced this together from other posts. I am trying to get this long print range to only print the sections that have information to print, if the next section does not have printable information, it should move to the next section until it has printed all ranges that fit my criteria and at the end reset the printrange to "".

I am missing or have end with's or missing end if's or have it really messed up.

Thanks in advance for any any help.


Code:
[HTML]Public Sub PRINT_COVERPAGE_CSR()
With Sheets("SERVICE_REPORT")
    .PageSetup.PrintArea = "$B$1:$I$" & .Range("N18").Value
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$1:$3"
        .PrintTitleColumns = ""
        .LeftFooter = Range("$B$208:$b$209").Text
        .RightFooter = Range("$F$208:$f$209").Text
    
    .PrintOut
   
    
    
    'PRINT SECTION 2 IF N57 >0
    If Range("N57").Value > "0" Then
With Sheets("SERVICE_REPORT")
    .PageSetup.PrintArea = "$B$19:$I$" & .Range("N57").Value
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$19:$20"
        .PrintTitleColumns = ""
     
    .PrintOut
  
    
    'PRINT SECTION 3 IF N89>0
    If Range("N89").Value > "0" Then
With Sheets("SERVICE_REPORT")
    .PageSetup.PrintArea = "$B$58:$I$" & .Range("N89").Value
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$58:$59"
        .PrintTitleColumns = ""
       
    .PrintOut
    'PRINT SECTION 4A IF N96>0
If Range("N96").Value > "0" Then
With Sheets("SERVICE_REPORT")
    .PageSetup.PrintArea = "$B$91:$I$" & .Range("N96").Value
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$91:$92"
        .PrintTitleColumns = ""
       
    .PrintOut
    'PRINT SECTION 4B IF N101>0
If Range("N101").Value > "0" Then
With Sheets("SERVICE_REPORT")
    .PageSetup.PrintArea = "$B$97:$I$" & .Range("N101").Value
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$97:$97"
        .PrintTitleColumns = ""
       
    .PrintOut
    'PRINT SECTION 5 IF N111>0
If Range("N111").Value > "0" Then
With Sheets("SERVICE_REPORT")
    .PageSetup.PrintArea = "$B$102:$I$" & .Range("N111").Value
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$102:$102"
        .PrintTitleColumns = ""
       
    .PrintOut
    'PRINT SECTION 6 IF N118>0
If Range("N118").Value > "0" Then
With Sheets("SERVICE_REPORT")
    .PageSetup.PrintArea = "$B$112:$I$" & .Range("N118").Value
    End With
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$112:$114"
        .PrintTitleColumns = ""
       
    .PrintOut
    'PRINT VESSELS SUMMARY IF N149>0
If Range("N149").Value > "0" Then
With Sheets("SERVICE_REPORT")
    .PageSetup.PrintArea = "$B$119:$I$" & .Range("N149").Value
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$119:$120"
        .PrintTitleColumns = ""
       
    .PrintOut
    'PRINT LINES SUMMARY IF N180>0
If Range("N180").Value > "0" Then
With Sheets("SERVICE_REPORT")
    .PageSetup.PrintArea = "$B$150:$I$" & .Range("N180").Value
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$150:$151"
        .PrintTitleColumns = ""
       
    .PrintOut
    'PRINT HT SUMMARY IF N197>0
If Range("N197").Value > "0" Then
With Sheets("SERVICE_REPORT")
    .PageSetup.PrintArea = "$B$181:$I$" & .Range("N197").Value
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$181:$182"
        .PrintTitleColumns = ""
       
    .PrintOut
    'PRINT MEMBRANE SUMMARY IF N204>0
If Range("N204").Value > "0" Then
With Sheets("SERVICE_REPORT")
    .PageSetup.PrintArea = "$B$198:$I$" & .Range("N204").Value
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$198:$199"
        .PrintTitleColumns = ""
       
    .PrintOut
    'PRINT ATTACHED PICTURES SUMMARY IF N207>0
If Range("N207").Value > "0" Then
With Sheets("SERVICE_REPORT")
    .PageSetup.PrintArea = "$B$204:$I$" & .Range("N207").Value
    With ActiveSheet.PageSetup
        .PrintTitleRows = "PICTURE ATTACHED"
        .PrintTitleColumns = ""
      .PrintOut
       End With
    
End Sub[/HTML]
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
This is without testing other than it did not generate a compile error.

Code:

Public Sub PRINT_COVERPAGE_CSR()
With Sheets("SERVICE_REPORT")
.PageSetup.PrintArea = "$B$1:$I$" & .Range("N18").Value
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$3"
.PrintTitleColumns = ""
.LeftFooter = .Range("$B$208:$b$209").Text
.RightFooter = .Range("$F$208:$f$209").Text
End With
.PrintOut
'PRINT SECTION 2 IF N57 >0
If .Range("N57").Value > "0" Then
.PageSetup.PrintArea = "$B$19:$I$" & .Range("N57").Value
With ActiveSheet.PageSetup
.PrintTitleRows = "$19:$20"
End With
End If
.PrintOut
'PRINT SECTION 3 IF N89>0
If .Range("N89").Value > "0" Then
.PageSetup.PrintArea = "$B$58:$I$" & .Range("N89").Value
With ActiveSheet.PageSetup
.PrintTitleRows = "$58:$59"
End With
End If
.PrintOut
'PRINT SECTION 4A IF N96>0
If .Range("N96").Value > "0" Then
.PageSetup.PrintArea = "$B$91:$I$" & .Range("N96").Value
With ActiveSheet.PageSetup
.PrintTitleRows = "$91:$92"
End With
End If
.PrintOut
'PRINT SECTION 4B IF N101>0
If .Range("N101").Value > "0" Then
.PageSetup.PrintArea = "$B$97:$I$" & .Range("N101").Value
With ActiveSheet.PageSetup
.PrintTitleRows = "$97:$97"
End With
End If
.PrintOut
'PRINT SECTION 5 IF N111>0
If Range("N111").Value > "0" Then
.PageSetup.PrintArea = "$B$102:$I$" & .Range("N111").Value
With ActiveSheet.PageSetup
.PrintTitleRows = "$102:$102"
End With
End If
.PrintOut
'PRINT SECTION 6 IF N118>0
If .Range("N118").Value > "0" Then
.PageSetup.PrintArea = "$B$112:$I$" & .Range("N118").Value
With ActiveSheet.PageSetup
.PrintTitleRows = "$112:$114"
End With
End If
.PrintOut
'PRINT VESSELS SUMMARY IF N149>0
If .Range("N149").Value > "0" Then
.PageSetup.PrintArea = "$B$119:$I$" & .Range("N149").Value
With ActiveSheet.PageSetup
.PrintTitleRows = "$119:$120"
End With
End If
.PrintOut
'PRINT LINES SUMMARY IF N180>0
If .Range("N180").Value > "0" Then
.PageSetup.PrintArea = "$B$150:$I$" & .Range("N180").Value
With ActiveSheet.PageSetup
.PrintTitleRows = "$150:$151"
End With
End If
.PrintOut
'PRINT HT SUMMARY IF N197>0
If .Range("N197").Value > "0" Then
.PageSetup.PrintArea = "$B$181:$I$" & .Range("N197").Value
With ActiveSheet.PageSetup
.PrintTitleRows = "$181:$182"
End With
End If
.PrintOut
'PRINT MEMBRANE SUMMARY IF N204>0
If .Range("N204").Value > "0" Then
.PageSetup.PrintArea = "$B$198:$I$" & .Range("N204").Value
With ActiveSheet.PageSetup
.PrintTitleRows = "$198:$199"
End With
End If
.PrintOut
'PRINT ATTACHED PICTURES SUMMARY IF N207>0
If .Range("N207").Value > "0" Then
.PageSetup.PrintArea = "$B$204:$I$" & .Range("N207").Value
With ActiveSheet.PageSetup
.PrintTitleRows = "PICTURE ATTACHED"
End With
End If
.PrintOut
End With
End Sub
Code:
 
Upvote 0
JLGWhiz,

Thanks for your reply. It worked for section 1 and 2, but then reprinted a bunch of the same ranges.

Do I need a reset print range with the if then statement?
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top