Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-09-28
7
Medium Priority
?
53 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 49

Assisted Solution

by:Martin Liss
Martin Liss earned 1000 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 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
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 create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

916 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