Solved

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

Posted on 2016-09-28
7
37 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 47

Assisted Solution

by:Martin Liss
Martin Liss earned 250 total points
ID: 41820808
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 81

Accepted Solution

by:
byundt earned 250 total points
ID: 41820878
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
ID: 41820884
Good grief.  Hadn't even seen that.  Thanks much guys!

--Ben
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 81

Expert Comment

by:byundt
ID: 41820956
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
ID: 41821691
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 81

Expert Comment

by:byundt
ID: 41821777
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
ID: 41821803
Thanks for providing that!   Dropped that in and took out the code I used.  

Greatly appreciated.

--Ben
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

735 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