Print VBA Code need minor assistance

boldcode

Active Member
Joined
Mar 12, 2010
Messages
347
Hello Everyone,

I want to fix my print VBA code, but I can't seem to find the error. What the code does is pretty much selects everything for Print starting from B5 to the last column. In B5 to the last column is blank and I want it blank.. In B6 to last column is where the title is. B7 to the last column is blank again and I want it that way. In other words Rows B5 and B7 just create blank rows so that my title in Row B6 to the last column looks prettier.

For Example this is what it would look like:

Blank Row
Investment
Blank Row

The funny thing about this code is that it works properly if I input a "space" Character in cell B5 and another one in cell B7. I don't want to do this.


Code:
Sub Print_InvestmentReport()
Dim lastcol As Integer
Worksheets("rpt_Investment").PageSetup.PrintArea = Worksheets("rpt_Investment").Range("B5").CurrentRegion.Address
lastcol = Worksheets("rpt_Investment").Cells(5, Worksheets("rpt_Investment").Columns.Count).End(xlToLeft).Column
On Error Resume Next  'continue if there are no PageBreaks
    With Worksheets("rpt_Investment").PageSetup
        .DisplayPageBreaks = False
        .PrintTitleRows = "$5:$8"
        .LeftMargin = Application.InchesToPoints(0.5)
        .RightMargin = Application.InchesToPoints(0.5)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .PrintGridlines = True
        .Zoom = False
        .CenterHorizontally = True
        .Orientation = xlPortrait
        .PaperSize = xlPaperLetter
        .FirstPageNumber = xlAutomatic
        .FitToPagesWide = 1
        .FitToPagesTall = 5
    End With
    Worksheets("rpt_Investment").PrintPreview
    
    Dim Answer As String
    Dim MyQuestion As String

    MyQuestion = "Do you still want to print this report?"

    'Display MessageBox
    If MsgBox(MyQuestion, vbYesNo, "Print Question") = vbNo Then
        Sheets("TOC").Select
        Exit Sub
    End If
    
    'Ask User How Many Copies does he want to Print
    Dim iCopies As String
 
    iCopies = Application.InputBox("How many copies do you want to print?", Type:=2)
 
    If iCopies <> vbNullString Then
     
    Worksheets("rpt_Investment").Columns("A:" & lastcol).EntireColumn.AutoFit
    Worksheets("rpt_Investment").PrintOut Copies:=iCopies, Collate:=True
    Else
    Exit Sub
    End If
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,224,548
Messages
6,179,448
Members
452,915
Latest member
hannnahheileen

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