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.
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