+ Reply to Thread
Results 1 to 8 of 8

Variable Print Area Macro Based on Cell Value

  1. #1
    Registered User
    Join Date
    10-14-2009
    Location
    Denver, CO
    MS-Off Ver
    Excel 2010
    Posts
    7

    Variable Print Area Macro Based on Cell Value

    I have a sheet of reference data (A1:I530), and I would like to create a macro that sets the print area for only rows that have a $ total in the H column, and a $ total in the I column. Stated another way, any row that is 0 in H or I columns wouldn't print. I only want this to apply to this individual sheet titled "Cost Codes".

    I think this would be much more economical both for time and paper use than conditional formatting.

    Does anyone have suggestions? Any help is greatly appreciated!


    Thank you
    Attached Files Attached Files
    Last edited by cuclay; 10-26-2009 at 06:07 PM.

  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: Variable Print Area Macro Based on Cell Value

    Hello cuclay,

    It can be done using VBA macros, if that is allowable in your case. Since the Print Area can only be set to a range of contiguous cells, it would require copying the selected data to another worksheet before it can be printed out. My guess would be some the formatting on the original sheet would need to copied over to the printout sheet. If you can post the workbook, that would be best. Change or remove any confidential or sensitive data beforehand.
    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
    10-02-2009
    Location
    Ottawa, Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Variable Print Area Macro Based on Cell Value

    An idea might be get a macro to first sort by column O and H. Then setting your print area to the first 0 cell in O or H. Printing then resort to original order.

  4. #4
    Registered User
    Join Date
    10-14-2009
    Location
    Denver, CO
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Variable Print Area Macro Based on Cell Value

    I've now posted the workbook. Could anyone help me with a macro that could sort the data on the 'Cost Codes' worksheet so that any rows with $0 in column I or H would be below those rows with $ totals in them. I would then print only the items that have $ totals, and leave the rows with zeros outside the print area. If I could then maintain the rest of the organization as close as possible after sorting, that would be helpful. May have to number the rows in cells in order to achieve this.


    Please let me know if you have thoughts. I can't tell you how much the help would be appreciated.


    Thanks again,

    Clay

  5. #5
    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: Variable Print Area Macro Based on Cell Value

    Hello Clay,

    The attached workbook has a button on the "Cost Codes" sheet to print out the non zero totals. Each row is added to the worksheet "Printout Data" to build the printable data in contiguous rows. You will probably need to adjust your margins on the "Printout Data" sheet. Let me know if this is what you want.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    10-14-2009
    Location
    Denver, CO
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Variable Print Area Macro Based on Cell Value

    Leith -

    This is amazing man! A couple questions for you:

    - Is there a way to make the 'Print Out' sheet preserve column headings from 'Cost Codes' sheet when the button is clicked?
    - Is there a way to remove the automatic print function? I only want to do so because we have a lot of networked printers, and my staff will need to manually print that sheet.

    And finally, do you have any recommendations on how I can begin to learn about creating macros for myself? I have seen a few posts on here where people were taught quite a lot from stem to stern. I am pretty adept in Excel itself, but have very limited experience with VBA.

    I honestly cannot tell you how much I appreciate your help. This is great.


    Thank you again,

    Clay

  7. #7
    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: Variable Print Area Macro Based on Cell Value

    Hello Clay,

    I can add the headings to the "Printout Data" sheet. Which ones do you want from the "Cost Codes"?

    I'll remove the automatic print function for you. Did it print out okay?

  8. #8
    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: Variable Print Area Macro Based on Cell Value

    Hello Clay,

    I didn't forget about you. I have made the changes to the workbook as you requested. Here is the updated macro that has been added to the attached workbook.
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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