+ Reply to Thread
Results 1 to 6 of 6

Programming to set print area and resize rows

  1. #1
    Registered User
    Join Date
    06-03-2009
    Location
    Mountain View, CA
    MS-Off Ver
    Excel 2003
    Posts
    46

    Programming to set print area and resize rows

    Hi All,

    I have a workbook containing a sheet that lists several possible line items in a price quote, and a pivot table containing those items selected by the user to be displayed (using checkboxes and a report filter).

    I want my users to have to do as little as possible to go from selecting the rows to include, to printing to pdf. As part of this, I'm wondering if there is a way to do two things:

    1. Automate the print area setting, and force to print to 1 page wide by 1 page tall
    2. Set the height of blank rows appearing between items to 1

    In the attached example, the code would not include the report filter row (row 2), resize rows 7, 9, 12, 14, 17, 19, 21, 24, 26, 28, 31, 33 to 1, and set the print area to A3:D33, on the basis of the fact that these rows include data.

    I have 0 programming experience but would love to learn how to make this happen. Thanks in advance for anyone who can help with this ...
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Programming to set print area and resize rows

    Hello prawer,

    I don't have Excel 2007, but this macro should work. This will set the Print Area for the ActiveSheet to "A3:D33". The rows you listed will be changed to a height of 1. The sheet will then print out.
    Please Login or Register  to view this content.
    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time.
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-03-2009
    Location
    Mountain View, CA
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: Programming to set print area and resize rows

    Leith,

    Thanks very much for your response. Unfortunately the settings I gave in my original post were examples -- I'd want the macro to identify the appropriate print area and then set it (ie it won't always be a3:d33 -- that depends on what the user has selected for inclusion from the source data. Likewise the row #s.

    By the way, I messed around with the macro recorder and it included this bit of code on the row resize step:

    Please Login or Register  to view this content.
    Will that work regardless of which rows have been selected for inclusion?
    Last edited by prawer; 08-28-2009 at 05:34 PM.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Programming to set print area and resize rows

    Hello prawer,

    Do you want to set the print area based the user's selection in the pivot table?

  5. #5
    Registered User
    Join Date
    06-03-2009
    Location
    Mountain View, CA
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: Programming to set print area and resize rows

    Not really, if you mean the cells that the user has selected. I have some very technologically shaky sales reps, so I want the code to set the print area to include the row labels of the pivottable (the part to the left of 'data items', which my pivot doesn't have) plus a few rows above (to separate it from my company logo, which is on top).

    Is there a way to refer to the array containing the row labels of the pivot table in VBA?

  6. #6
    Registered User
    Join Date
    06-03-2009
    Location
    Mountain View, CA
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: Programming to set print area and resize rows

    Hi All. I hate to 'bump' but I know this is possible, I just don't have the programming chops to make it happen. I'm at the point where I know how to select the row labels in a pivot table, but I don't know how to edit the array reference to 'bump it up' a few rows ...

+ 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