+ Reply to Thread
Results 1 to 5 of 5

Reset a volatile print area

Hybrid View

  1. #1
    Registered User
    Join Date
    07-18-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2016
    Posts
    25

    Reset a volatile print area

    In advance, thanks so much for your time and attention.

    I am using a pivot table to query a large spreadsheet for select data. The pivot table is always four columns wide but can vary widely in length. I have recorded a macro to select the appropriate area to print, format the selected area however, I am not able to get the macro to "re-define" the print area after the pivot table is refreshed and the appropriate area is selected. The following code does all the above stated tasks nicely but the ActiveSheet.PageSetup.PrintArea = "$B$10:$E$19" line fails me. Clearly I need help getting around the absolute range reference.

    Thanks again.


    Sub RefreshPivotClassType()
    '
    ' RefreshPivotClassType Macro
    '
    
    '
        ActiveSheet.PivotTables("PivotClassType").PivotCache.Refresh
        Columns("B:B").Select
        Selection.ColumnWidth = 15
        Columns("C:C").Select
        Selection.ColumnWidth = 15
        Columns("D:D").Select
        Selection.ColumnWidth = 45
        Columns("E:E").Select
        Selection.ColumnWidth = 9
        Range("E9").Select
        Range(Selection, Selection.End(xlDown)).Select
        Range(Selection, Selection.End(xlToLeft)).Select
        With Selection
            .HorizontalAlignment = xlGeneral
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        ActiveSheet.PageSetup.PrintArea = "$B$10:$E$19"
        Range("B9").Select
    End Sub

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,953

    Re: Reset a volatile print area

    You should post a workbook; however you might try:

    Dim PrtArea As String
    ActiveSheet.PivotTables("PivotClassType").PivotCache.Refresh
    
    'if B10 is the upper left corner of the PT
    
    PrtArea = Range("B10").currentregion.address     
    ...
    etc...
    ...
    ActiveSheet.PageSetup.PrintArea = PrtArea
    ...
    etc...
    Last edited by protonLeah; 12-16-2015 at 05:44 PM.
    Ben Van Johnson

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,694

    Re: Reset a volatile print area

    or maybe
    ActiveSheet.PageSetup.PrintArea = "$B$10:$E$" & Range("E" & Rows.Count).End(xlUp).Row
    Have a quick read here.
    http://stackoverflow.com/questions/1...cel-vba-macros

    http://www.businessprogrammer.com/po...-using-select/

    http://dailydoseofexcel.com/archives...-and-activate/

  4. #4
    Registered User
    Join Date
    07-18-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2016
    Posts
    25

    Re: Reset a volatile print area

    Your suggestion worked well. I also thank you for the reading material. My dabblings in VBA clearly pointed to the abhorrence of .Select but the readings confirmed it and gave me viable options. Thanks so much.

  5. #5
    Registered User
    Join Date
    07-18-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2016
    Posts
    25

    Re: Reset a volatile print area

    Quote Originally Posted by protonLeah View Post
    You should post a workbook; however you might try:

    Dim PrtArea As String
    ActiveSheet.PivotTables("PivotClassType").PivotCache.Refresh
    
    'if B10 is the upper left corner of the PT
    
    PrtArea = Range("B10").currentregion.address     
    ...
    etc...
    ...
    ActiveSheet.PageSetup.PrintArea = PrtArea
    ...
    etc...
    I truly thought I should (post a workbook) but it would have required a full rebuild as the data in the workbook is confidential... no, very confidential.

    That stated, I used your suggestion and it worked as you thought it might. jolivanes suggestion worked as well. I am a power Excel user when it comes to formulas and other "internal" Excel features. However, I have only dabbled in VBA. The myriad of coding options is often daunting to a VBA greenhorn like me. The help offered quickly and succinctly by the forum regulars is not only immeasurably helpful, but also refreshing. Thank you all so much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Dynamic Print Area Reset by Print Preview
    By dhpeter83 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-24-2015, 04:17 PM
  2. Replies: 1
    Last Post: 02-12-2013, 12:16 PM
  3. How to add icon Reset print area?
    By toplisek in forum Excel General
    Replies: 5
    Last Post: 03-18-2010, 05:45 AM
  4. Replies: 8
    Last Post: 05-23-2007, 06:39 AM
  5. [SOLVED] How do you set up a macro to reset the print area?
    By Stuck2 in forum Excel General
    Replies: 0
    Last Post: 01-30-2006, 11:55 AM
  6. Replies: 4
    Last Post: 10-08-2005, 03:05 PM
  7. Volatile print area
    By stevepain in forum Excel General
    Replies: 6
    Last Post: 07-20-2005, 04:05 PM

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