+ Reply to Thread
Results 1 to 9 of 9

Excel 2007 : Print Macro for occupied cells only and multiple sheets...

  1. #1
    Registered User
    Join Date
    10-05-2010
    Location
    Toledo
    MS-Off Ver
    Excel 2003-2007
    Posts
    9

    Print Macro for occupied cells only and multiple sheets...

    Hello,

    First I want to thank the forum for the many posts that helped me to achieve setting up the protect issues we were having with the conversion to 2007. It was tough finding the topics that were specific to the issue but I did get there because of the work by the people on this forum. A big thank you.

    Now I have a situation where the print macro is shot. Used to be set up to print 3 specific sheets (2 copies of each). In 2003 it seemed to work fine. In 2007 it is not working well at all.

    Here is what is happening first.

    There are 3 sheets. Two of them are BOM sheets which means that the total lines involved will vary each time the sheet is used. Unfortunately it prints out everything in the sheet (including 4 pages of empty cells) each time.

    I had found a topic that covered this but I can't find it again. There are just too many posts to try and go through. Now that I am on hour 2 trying to find this again I am at the point of starting this thread.

    The second issue is that the boxes and such are skewed now. We will have the lines drawn in surrounding a set number of cells and when we print they are usually a lot bigger covering other cells. The same thing happens with Logos and such. Maybe this should be a different topic or I may be able to find it elsewhere. Thought I would mention it.

    Any help or suggestions on this would be greatly appreciated!

    Thank you,

    Mike

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,105

    Re: Print Macro for occupied cells only and multiple sheets...

    Sorry, my imagination just isn't up to this task.

    A copy of the macro would be helpful; better still, a sample workbook with the code that can be tested in both versions of Excel

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    10-05-2010
    Location
    Toledo
    MS-Off Ver
    Excel 2003-2007
    Posts
    9

    Re: Print Macro for occupied cells only and multiple sheets...

    Sorry about that. I was worried it wouldn't make too much sense.

    Here is the issue (and I will copy the macro next).

    We have a document with 8 sheets. The first 3 are input sheets. Information placed in these will then input into 4 other sheets.

    In the end we have these 4 sheets that we want printed out (2 copies of each).

    They are the BOM, Labor Cost Estimate, Cost Summary and a W.O. sheet.

    In the W.O. sheet we have a print tab with the macro that will print 2 copies of each of the sheets. The issue is that the BOM and Labor Cost Estimate sheets will vary in length per each use. When we print them with the Print tab on the W.O. sheet we get 4 empty pages of each. We want the macro to be set to print only the page break areas that have cells with data in them.

    Here is the macro:

    Please Login or Register  to view this content.
    I had come across some code in other discussions on this site where a way to print only the occupied cells on a sheet with a macro was put together. First, I cannot find that thread again. Second, this is a little different because we are dealing with multiple sheets.

    I had made an attempt to put the code in but it just didn't work out. Here is what I had there:

    Please Login or Register  to view this content.
    A second issue is with the output of the documents. When I send them to PDF they show up nice and neat and fit into the PDF. All of the lines and boxes are in the same scale and everything looks as it does in the Excel document. However, when I send them to the printer the prints cut off the right side of the page and the boxes and such are scaled up which obscures other items in the document.

    Thank you very much for your time on this. This site has helped me tremendously with the switch to 2007.

    Best regards,

    Mike

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,105

    Re: Print Macro for occupied cells only and multiple sheets...

    Personally, I'd still like to see a sample workbook.

    If the information is sensitive, delete anything that you don't want to share. In practical terms, I'd only want to know where the last (bottom right) cell is and the formatting.

    In my experience, the only reason for setting a Print Range is to limit the columns or rows that you want to print. For example, if you have "working" data or helper columns at the right hand side. Or if you have rows that are formatted ready for data but which are blank. From the macro, the former is not true but the latter could be.

    Interestingly, you print out the first and last sheets but set the print area for the two in the middle.

    Your routine runs through for me on Excel 2003 and 2007. The only changes were to comment out the execution of Macro3 which I don't have and PrintOut to PrintPreview.

    That said, I can only guess at what your sheets look like, what the margins are set to, whether you are shrinking to fit, etc ...

    Regards

  5. #5
    Registered User
    Join Date
    10-05-2010
    Location
    Toledo
    MS-Off Ver
    Excel 2003-2007
    Posts
    9

    Re: Print Macro for occupied cells only and multiple sheets...

    I have sent you a private message on this.

    However, I wanted to reply on the site in case there is a contributor that may have a fix in mind.

    I can't post the document with the sensative info removed. It corrupts the macros. I can't take the time to reset all of the values to "x" since with are dealing with thousands of parts broken up into sections divided by objects and other text throughout the document. I only have so much time allotted to come up with a fix for this.

    The reason we have 2 sheets set to simply print and then 2 sheets that we want to adjust on a project by project has a simple answer.

    The 2 sheets we want to just print have established ranges. They are simply summary documents only. The range of cells occupied will never change.

    The other two sheets are for materials and labor. These two sheets will change on a day by day, project by project basis. There will be dozens of different people using this every single day for 2 or 3 or more different projects. Some projects may only fill in 1 sheet worth of material and labor. But then there will be others that may use 4 sheets or more.

    Most projects will use only 1 to 2 sheets. How the macro is set now we will get 2 copies of the summary sheets (which is what we want), 2 copies of the BOM and Labor sheets (which is what we want) but then 2 copies each of up to 4 blank pages.

    With hundreds of projects being run each week you can see how this will add up fast.

    If it can't be done I will simply tell them that we will have to print out each sheet individually and set the print range on a per project basis. I am simply trying to keep it as simple for them as possible.

    Thank you all ahead of time for your help.

    Mike

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,105

    Re: Print Macro for occupied cells only and multiple sheets...

    I am away at the moment without my laptop so I can't look at the workbook. A couple of thoughts though. First, I think you should step through your code and see what exactly you are getting as your LastCell.Address. I prefer to establish the last row based on the contents of a specific column as I find this more reliable.

    For example:

    lLastRow = Range("A" & Rows.Count).End(xlUp).Row

    Then use:

    Range(Cells(1,1), Cells(lLastRow,15)).Address

    as the PrintArea (adjust the column as required).

    I'm sorry, I'm trying to respond using an iPod Touch and I'm not finding it easy!

    Regards

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,105

    Re: Print Macro for occupied cells only and multiple sheets...

    I have sent the code to you by PM and also by email.

    Regards

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Print Macro for occupied cells only and multiple sheets...

    Quote Originally Posted by TMShucks View Post
    I have sent the code to you by PM and also by email.

    Regards

    Why, questions & answers should be only posted on the Forum
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,105

    Re: Print Macro for occupied cells only and multiple sheets...

    Because the code was specific and relevant only to the OP.

+ 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