+ Reply to Thread
Results 1 to 15 of 15

Set print Area

  1. #1
    Registered User
    Join Date
    11-14-2007
    Posts
    19

    Set print Area

    Is it possible for a macro to set the print area based on cells that have data? Here is what i am wanting to print.
    A1:G1000 but only if Data is present (each row has hidden formulas) and I want Row 2 to repeat at the top of every page. I tried this with the Set print area but i get a lot of blank pages with only row 2


    not sure if it matters but Columns H-N have data that i do not want printed

    Thanks

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    perhaps something like this:
    Please Login or Register  to view this content.
    everytime you change a worksheet the print area will change, however the range will depend on data in column G so if you have 100 rows of data in column A and only 10 in G then the print area will be A1:G10, if you swap the A and the G around in the code then your print area would be A1:G100.
    Not all forums are the same - seek and you shall find

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Perhaps in the Workbook_BeforePrint event rather than the Worksheet_Change event?

  4. #4
    Registered User
    Join Date
    11-14-2007
    Posts
    19
    Thanks for your responses. I tried both and it doesnt seem to work. Still prints 25+ pages. Any suggestions?

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Would you please post a sample workbook that illustrates the problem, and describe your desired result?

  6. #6
    Registered User
    Join Date
    11-14-2007
    Posts
    19

    Smile

    Blank - 2008.zip

    Not sure if this is what you wanted or not. The desired result would be that if only 32 rows have data in them then only print 32 Rows, not 25 pages of blank paper with Row 2 being repeated on each page. Data is added daily until the end of the month so the list gets bigger each day.

    Thaks Again

  7. #7
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    It doesnt work because you have pasted the code in to a standard module (module 8) it needs to be pasted in to the "ThisWorkbbok" module!
    you need the code to look like this:
    Please Login or Register  to view this content.
    Last edited by Simon Lloyd; 11-29-2007 at 06:48 PM.

  8. #8
    Registered User
    Join Date
    11-14-2007
    Posts
    19

    Smile

    thank you Simon,
    I pasted it first in the Thisworkbook module of the Personal.xls file so it can be used in other workbooks. When it didnt work i tried it in the file itself. Let me try again

  9. #9
    Registered User
    Join Date
    11-14-2007
    Posts
    19
    Should this effect show in print preview? does the macro run Automatically or do i need to create a button?

  10. #10
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    it runs automatically everytime you change something on any worksheet.

    Take a look at the attached, add and remove data to see the effect, remember though...setting the print area will not set your margins, you have to do that in page setup.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    11-14-2007
    Posts
    19

    Lightbulb

    Thanks simon,
    That does work perfectly for what i want. but when i put in effect for my workbook it doesnt do anything. I got to looking at the thisworkbook module and i have the following code already in there to save the workbook after input of data. Could this be affecting it?

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-14-2007
    Posts
    19
    I did some research and learned that you cant have 2 private sub Workbook sheet change or you will get an Ambigous Name detected error. So i guess i need to make these 2 codes in one. I Tried but it doesnt seem to work. I am still learning this so any help here is appreciated. I will post the 2 codes and maybe someone can help make them in one
    Thanks

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    11-14-2007
    Posts
    19
    im still trying to get theses two codes to work in the same workbook. No luck yet

  14. #14
    Registered User
    Join Date
    11-14-2007
    Posts
    19

    Talking

    I finally Got it figured out. Thanks Simon and SHG for your help.

  15. #15
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Please Login or Register  to view this content.
    try this, the sub that you have in the ThisWorkBook module called Sub StopAllEvents() will not work, but i have incorporated what you want in the code above!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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