Solved

Print Preview in Excel 2010 generating 2 blank pages at end of document

Posted on 2016-09-28
7
28 Views
Last Modified: 2016-09-29
Hi,

I have a spreadsheet I create from a subset of another one with a VBA routine.  The spreadsheet is getting 2 extra pages at the end of it in print preview mode that I can't explain.  Anyone have any suggestions as to what could be causing this?

The VBA code I've used in the past to mitigate this is:

    ' The following forces a recalculation of what the actual used range is for this
    ' tab.  Sometimes Excel prints blank pages; this fixes that.
    a = ActiveSheet.UsedRange.Rows.Select
   
    With ActiveSheet.PageSetup
      .Orientation = xlLandscape
      .PaperSize = xlPaperLetter
      .PrintTitleRows = "$20:$20"
      .PrintTitleColumns = ""
      .Zoom = 100
      .FitToPagesWide = 1
      '.FitToPagesTall = 1
      .LeftFooter = "&""Calibri""&08" & "Centers for Medicare and Medicaid Services" & Chr(10) & _
                    "FMQAI - Hospital Outpatient Quality Reporting Program Support Contractor"
      .RightFooter = "&""Calibri""&08 Page &P of &N "
   
    End With

But that doesn't seem to be working in this instance.  

Thanks!

--Ben
000001_Hospital-OQR-Program-Claims-.xlsx
0
Comment
Question by:Ben Conner
  • 3
  • 3
7 Comments
 
LVL 45

Assisted Solution

by:Martin Liss
Martin Liss earned 250 total points
Comment Utility
Select the area that you want to print and then from the Page Layout tab select Print Area and then Set Print Area, After that print preview will no longer show the blank pages.
0
 
LVL 80

Accepted Solution

by:
byundt earned 250 total points
Comment Utility
In your file, column G is part of the Print Area, but does not fit on the page. As a result, you print two extra pages to get column G, even though it is blank.
0
 

Author Comment

by:Ben Conner
Comment Utility
Good grief.  Hadn't even seen that.  Thanks much guys!

--Ben
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 80

Expert Comment

by:byundt
Comment Utility
Immediately after opening the file, I checked the value of ActiveSheet.UsedRange.Address, and found it was $A$1:$G$50. A print preview showed four pages. I thereupon deleted column G to reset the used range to $A$1:$F$50. After doing so, the printout took only two pages.

Next, I opened another copy of the file and deleted column G. Print preview annoyingly still showed four pages. But when I calculated the used range in VBA, it displayed the correct answer and the print preview subsequently showed only two pages.

Conclusion: you must execute a VBA statement that references the UsedRange property of the worksheet to actually reset it.

I also found an irritatingly sticky Custom Paper Size setting in the Page Setup dialog. I could not change it at all. The statement trying to change it also errored out in the macro posted in the question body. To overcome this problem, I used File...Print and then clicked on the Printer Properties link, and changed the Media type from "Unspecified" to "Plain".
0
 

Author Comment

by:Ben Conner
Comment Utility
Yes, I see that now...when I had the code in the vba:
    a = ActiveSheet.UsedRange.Rows.Select

it pulled in column G.  Is there a different approach to calculating the used range I should try?

I did beat it into submission by adding:
       ActiveWindow.View = xlPageBreakPreview
       ActiveSheet.PageSetup.PrintArea = "$A:$F"

but I don't consider that to be optimal.  Wish I knew why it chose a blank column as part of the spreadsheet.

--Ben
0
 
LVL 80

Expert Comment

by:byundt
Comment Utility
Ben,
When resetting the used range, I prefer to count the number of rows or columns and assign the value to a variable. Selecting a range is unnecessary.

For your particular problem, the following code may be used to reset the used range so printing needs only two pages. It deletes columns from the right until there are one or more data in the rightmost column in the used range.

Brad

Sub ResetUsedRangeColumns()
Dim i As Long, nCols As Long
Dim rg As Range
With ActiveSheet
    Do
        Set rg = .UsedRange
        nCols = rg.Columns.Count
        If Application.CountA(rg.Columns(nCols)) > 0 Then
            Exit Do
        Else
            rg.Columns(nCols).EntireColumn.Delete
        End If
        nCols = .UsedRange.Columns.Count
        i = i + 1
        If i > 100 Then Exit Do
    Loop
End With
End Sub

Open in new window

0
 

Author Comment

by:Ben Conner
Comment Utility
Thanks for providing that!   Dropped that in and took out the code I used.  

Greatly appreciated.

--Ben
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now