+ Reply to Thread
Results 1 to 4 of 4

Set Print Area for changing ranges on a sheet

  1. #1
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Set Print Area for changing ranges on a sheet

    Hello,

    I have the following code to set the print area on a tab. I thought I had it so that it will find the last used row but it is still setting up with extra blank pages. The data on the tab can change monthly but the columns will remain the same. Any help?

    Please Login or Register  to view this content.
    Public Sub Workbook_BeforePrint2()
    Dim lastrow As Long
    lastrow = Worksheets("By Mall - In Place").Range("AD1048576").End(xlUp).Row
    Dim rng As Range
    Set rng = Worksheets("By Mall - In Place").Range("AD1:AS" & lastrow)
    Worksheets("By Mall - In Place").PageSetup.PrintArea = rng
    ActiveWindow.ActiveSheet.PrintPreview
    End Sub
    Please Login or Register  to view this content.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Set Print Area for changing ranges on a sheet

    Maybe:


    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Re: Set Print Area for changing ranges on a sheet

    Thanks xladept but that did not work. The problem is there are formulas that go beyond the data that is showing values. So there are blank cells but they have formulas in them. The macro is thinking those blank rows should be part of the print range and I do not want them to be. Any suggestions for that?

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Set Print Area for changing ranges on a sheet

    Hi A,

    This will let you know if there is a formula in a specific cell - maybe you can adapt it:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1