+ Reply to Thread
Results 1 to 4 of 4

Excel VBA set print area with user input

  1. #1
    Registered User
    Join Date
    10-24-2012
    Location
    SW US
    MS-Off Ver
    Excel 2007 & 2003
    Posts
    4

    Excel VBA set print area with user input

    Several hours trying to get this to work. Am defeated.

    I have a budget worksheet with Column A containing Budget Categories and Row 8 containing MM/YYYY.

    I have Column A and Row 8 as 'fixed' so that they print on each page.

    A user might want only 4 (consecutive) months on a report.

    I would like to have a macro that Says: "Select the Beginning Month of your Report". User selects cell that has Mar-2015 . Then, "Select the Ending Month of your Report". User selects Jun-2015 .

    The number of rows to print is hard-coded at 80, so (with Column A containing Cats and months beginning with Jan-2015 in Column B, the Print Area would be D8:H80).

    I've tried numerous ways of 'assembly-ing' the Print Area based on both a Column number extracted from the user input for beginning and ending -- and I've been able to extract the Address for the Begin Date cell the user selected (and End Date) -- but I don't seem to understand how and when to use Address in the print area.

    Here's one of several I've tried -- and there is much amiss with this one....

    Please Login or Register  to view this content.
    Thank you.
    Last edited by swtrader; 12-29-2015 at 12:50 PM.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Excel VBA set print area with user input

    Hi swtrader,

    I understand your frustration. You were very close to solving the problem. The secret is the understanding of the difference between variables and objects. Until the difference is understood, there will probably be a lot of head scratching and bad words.

    The Page Setup Print Area expects the address as a String, that is why you would need the .Address if you used a Range object (MyPrntRng.Address).

    Another possible solution, is to declare the Print Range to contain all your data, and to Hide the Columns that you don't want printed.

    I will answer attempt to your question with the following 4 examples:

    The first example is a corrected copy of your original code, with the changes in red.
    Please Login or Register  to view this content.
    The second example only needs one input, the entire Print Range
    Please Login or Register  to view this content.
    The Third Example is similar to the first example, but restricts date selection o Dates in Column 'A'. Then it is assumed the print area extends to Column 'G' and creates a 'Final Print Area'.
    Please Login or Register  to view this content.
    Finally, a simple example of how columns could be hidden:
    Please Login or Register  to view this content.

    I hope this helps.

    Lewis
    Last edited by LJMetzger; 12-29-2015 at 01:36 PM. Reason: Rewrite of Example 3; Added Example 4; Added sample file

  3. #3
    Registered User
    Join Date
    10-24-2012
    Location
    SW US
    MS-Off Ver
    Excel 2007 & 2003
    Posts
    4

    Re: Excel VBA set print area with user input

    Very helpful, Lewis. Thank you!! And thanks for pointing out the tutorial.

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Excel VBA set print area with user input

    Thanks for the rep points. It was my pleasure to help.

    Thanks for putting in the CODE TAGS. The moderators run a tight ship, but it makes for a better experience for all.

+ 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. Populate a Column from a User Input Area
    By CDEG in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-04-2015, 05:40 PM
  2. [SOLVED] Setting print area based on input
    By QAChaska in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-03-2013, 01:37 PM
  3. [SOLVED] Saving a Print Area as PDF onto a user defined folder location
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-10-2013, 10:27 AM
  4. Replies: 1
    Last Post: 02-12-2013, 12:16 PM
  5. print area a variable from input
    By waltvg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-07-2012, 03:57 AM
  6. Print area changing with input
    By Fast Forward in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-13-2007, 08:11 PM
  7. [SOLVED] Print Area:a user to navigate to a text file
    By MarkN in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-15-2006, 09:45 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