+ Reply to Thread
Results 1 to 5 of 5

Dynamic Print Areas with VBA

  1. #1
    Registered User
    Join Date
    05-24-2018
    Location
    London
    MS-Off Ver
    2013
    Posts
    4

    Post Dynamic Print Areas with VBA

    I have an excel sheet with 7 different 'forms' on it ranging from A1:O43, A44:O77, A78:O111, A112:O145, A146:O167, A168:O189, A190:O220. Each form is on 1 page. If a form is not used, I have made buttons to hide the form on the workpage (code below) but it would still print a blank page (I know you can manually change print areas/print selection). The last form (A190:O220) is a totals page which should only be added to the print area if 2 or more forms are used. Im looking for a solution to include/remove these forms from the print area when their respective buttons are clicked to show/hide them from the worksheet (if possible). If this is not possible, an alternative would be to have a new macro to set the print area to current active cells (not including the hidden rows of forms not in use). Im not advanced at coding so I have essentially been going through each possible combination of forms (code below) that have a value on them to include in the print area. Im sure there is a much faster method out there.. any help would be appreciated. Thanks!

    Button to hide/show 1 of the forms (for example):
    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 05-24-2018 at 10:06 AM.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Dynamic Print Areas with VBA

    Hi there,

    See if the attached workbook does what you need - it uses the following code:

    Please Login or Register  to view this content.
    The highlighted values may be altered to suit your eventual needs.

    Feel free to ask about anything you need to know regarding the above code.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    05-24-2018
    Location
    London
    MS-Off Ver
    2013
    Posts
    4

    Re: Dynamic Print Areas with VBA

    Looked at the excel file attached.. the print preview still shows a blank page when a form is hidden. I actually came across a solution on mrexcel forum and made adjustments to suit my needs. It wont let me post links unfortunately :/

    Thanks for the help anyways!

  4. #4
    Registered User
    Join Date
    05-24-2018
    Location
    London
    MS-Off Ver
    2013
    Posts
    4

    Re: Dynamic Print Areas with VBA

    This is the code from the page since i cant link it:
    Please Login or Register  to view this content.
    Last edited by excely1; 05-25-2018 at 08:54 AM.

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Dynamic Print Areas with VBA

    Hi again,

    Many thanks for your feedback and for the code you discovered.

    What you encountered seems strange . . . I downloaded and opened the file I posted earlier, "hid" some of the ranges (by removing the text from various red cells) and then ran the code. The resulting PrintPreview showed one page for each of the non-hidden ranges, but NO blank pages - as Alice said, curiouser and curiouser

    Anyway, glad to hear that you now have a solution that works for you.

    Regards,

    Greg M

+ 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. Want to print only two print areas in one sheet(combined)
    By jayarajmarydasan in forum Excel General
    Replies: 1
    Last Post: 05-04-2016, 04:24 AM
  2. Macro to print multiple print areas on one page.
    By morangeman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2015, 12:13 PM
  3. Create buttons to print defined print areas
    By nwpassage in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2015, 11:17 PM
  4. Replies: 0
    Last Post: 05-23-2014, 01:05 PM
  5. VBA code to print several print areas in one worksheet
    By ABSTRAKTUS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-25-2010, 03:24 PM
  6. How to print multiple print areas on the same page.
    By Dalilah in forum Excel General
    Replies: 5
    Last Post: 08-27-2008, 09:05 AM
  7. printing multiple print areas with a print dialog box
    By LHaro in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-17-2005, 05:05 PM

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