Help with a printarea / printing macro

Thebatfink

Active Member
Joined
Apr 8, 2007
Messages
410
Hi,

I'm pulling my hair out here. I have produced this code (snippet below) and it appears to cycle through perfectly and do what I want, but it never prints what I am expecting. For instance -

Code:
Private Sub printselected_Click()
With Sheets("Charts").PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0.354330708661417)
        .RightMargin = Application.InchesToPoints(0.354330708661417)
        .TopMargin = Application.InchesToPoints(0.393700787401575)
        .BottomMargin = Application.InchesToPoints(0.393700787401575)
        .HeaderMargin = Application.InchesToPoints(0.511811023622047)
        .FooterMargin = Application.InchesToPoints(0.511811023622047)
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .CenterHorizontally = True
        .CenterVertically = True
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = xlPaperA4
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
        .PrintErrors = xlPrintErrorsDisplayed
    End With
    bResponse = Application.Dialogs(xlDialogPrinterSetup).Show
    If bResponse = False Then
        MsgBox "Printing cancelled by User"
        Exit Sub
End If
If aa1toggle.Caption = "Print aa1 Charts" Then
Call printaa1charts
End If
If aa2toggle.Caption = "Print aa2 Charts" Then
Call printaa2charts
End If
If aa3toggle.Caption = "Print aa3 Charts" Then
Call printaa3charts
End If
If aa4toggle.Caption = "Print aa4 Charts" Then
Call printaa4charts
End If
If ab1toggle.Caption = "Print ab1 Charts" Then
Call printab1charts
End If
If ab2toggle.Caption = "Print ab2 Charts" Then
Call printab2charts
End If
If ab3toggle.Caption = "Print ab3 Charts" Then
Call printab3charts
End If
End Sub

Private Sub printaa1charts()
If aa18 = True Then
Sheets("Charts").Range("j1").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$1:$q$43"
    Sheets("Charts").PrintOut
If aa116 = True Then
    Sheets("Charts").Range("j45").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$45:$q$87"
    Sheets("Charts").PrintOut
    Sheets("Charts").Range("j1").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$1:$q$43"
    Sheets("Charts").PrintOut
End If
If aa124 = True Then
    Sheets("Charts").Range("j90").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$90:$q$132"
    Sheets("Charts").PrintOut
    Sheets("Charts").Range("j45").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$45:$q$87"
    Sheets("Charts").PrintOut
    Sheets("Charts").Range("j1").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$1:$q$43"
    Sheets("Charts").PrintOut
End If
If aa132 = True Then
    Sheets("Charts").Range("j134").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$134:$q$176"
    Sheets("Charts").PrintOut
    Sheets("Charts").Range("j90").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$90:$q$132"
    Sheets("Charts").PrintOut
    Sheets("Charts").Range("j45").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$45:$q$87"
    Sheets("Charts").PrintOut
    Sheets("Charts").Range("j1").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$1:$q$43"
    Sheets("Charts").PrintOut
End If
If aa140 = True Then
Sheets("Charts").Range("j178").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$178:$q$220"
    Sheets("Charts").PrintOut
    Sheets("Charts").Range("j134").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$134:$q$176"
    Sheets("Charts").PrintOut
    Sheets("Charts").Range("j90").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$90:$q$132"
    Sheets("Charts").PrintOut
    Sheets("Charts").Range("j45").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$45:$q$87"
    Sheets("Charts").PrintOut
    Sheets("Charts").Range("j1").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$1:$q$43"
    Sheets("Charts").PrintOut
End If
End Sub

Code:
aa1toggle.Caption = "Print aa1 Charts" (is true)
aa116 = true (is true)

so it should do

Code:
    Sheets("Charts").Range("j45").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$45:$q$87"
    Sheets("Charts").PrintOut
    Sheets("Charts").Range("j1").Value = Now
    Sheets("Charts").PageSetup.PrintArea = "$a$1:$q$43"
    Sheets("Charts").PrintOut

It correctly inserts the .Value Now into both the cells BUT it prints out two copies of "$a$1:$q$43"?!?! Obviously I'm doing something wrong but I can't see what it is :(

Any help would be greatly appreciated and save whats left of my greying hair!!

Thanks
Batfink
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,214,823
Messages
6,121,777
Members
449,049
Latest member
greyangel23

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