+ Reply to Thread
Results 1 to 16 of 16

Printing a worksheet if a cell has a value

  1. #1
    Forum Contributor
    Join Date
    02-17-2005
    Location
    Wokingham
    MS-Off Ver
    365
    Posts
    101

    Printing a worksheet if a cell has a value

    Hi

    Is it possible to print a worksheet if a cell has a value?

    I have 7 worksheets and want the print macro to only print those that contain data in a particular cell.

    Any ideas would be really appreciated.

    Steven811
    Last edited by Steven811; 05-02-2010 at 06:45 AM.

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

    Re: Printing a worksheet if a cell has a value

    Somethig like

    Please Login or Register  to view this content.
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    02-17-2005
    Location
    Wokingham
    MS-Off Ver
    365
    Posts
    101

    Re: Printing a worksheet if a cell has a value

    Thanks for that but, I can't get it to work and I think I haven't explained it very clearly.

    My aim is to have a macro that looks in cell K66 for example and if it contains "1" it will print Sheet 1, then it looks in K67 for "2" and it will then print Sheet 2, if there is no value in the cell then that particular page does not print, this will run for any combination of the 7 worksheets.

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Printing a worksheet if a cell has a value

    Your initial description ...

    I have 7 worksheets and want the print macro to only print those that contain data in a particular cell.
    ... reads as if there is an individual cell in each worksheet that determines whether or not the sheet should be printed.

    Please make sure to state your requirements in full and precisely to avoid wasting time.

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

    Re: Printing a worksheet if a cell has a value

    That's nothing like your initial request. If you use 1 for print & 0 for no print then
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-17-2005
    Location
    Wokingham
    MS-Off Ver
    365
    Posts
    101

    Re: Printing a worksheet if a cell has a value

    Thank you for your assistance.

    I apologise for my poorly written thread

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

    Re: Printing a worksheet if a cell has a value

    I forget to say that when you use the code change PrintPreview to PrintOut

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    Last edited by royUK; 05-01-2010 at 07:18 AM.

  8. #8
    Forum Contributor
    Join Date
    02-17-2005
    Location
    Wokingham
    MS-Off Ver
    365
    Posts
    101

    Re: Printing a worksheet if a cell has a value

    I'm afraid that this is clearly beyond my very limited vba abilities, I'm getting a compile error "invalid inside procedure" and am unclear how to proceed.

    My code now looks like:

    Please Login or Register  to view this content.

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

    Re: Printing a worksheet if a cell has a value

    You have placed all the example code within your button. This will only work if you use 1 to print & zero to not print in the cells

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    02-17-2005
    Location
    Wokingham
    MS-Off Ver
    365
    Posts
    101

    Re: Printing a worksheet if a cell has a value

    Hi Roy, thanks for that, I think I'm nearly there.

    For some reason it prints Sheet 1 to 4 and not to Sheet 7 as well as printing Sheet 3 where I've set the value at 0, the rest are set at 1. I've checked the cell contents and they appear to be identical. Can I also exclude a specific worksheet?

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

    Re: Printing a worksheet if a cell has a value

    The sheets are printing according to the order they are in the workbook

  12. #12
    Forum Contributor
    Join Date
    02-17-2005
    Location
    Wokingham
    MS-Off Ver
    365
    Posts
    101

    Re: Printing a worksheet if a cell has a value

    I've attached the workbook. The print button is on the machine logo costs sheet which is also the only worksheet that I do not wish to print.
    Attached Files Attached Files

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

    Re: Printing a worksheet if a cell has a value

    So why not simply exclude that sheet? If you want touse the list on the sheet
    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    02-17-2005
    Location
    Wokingham
    MS-Off Ver
    365
    Posts
    101

    Re: Printing a worksheet if a cell has a value

    Hi Roy, brilliant!

    You can't believe what a relief that is, it works perfectly.

  15. #15
    Registered User
    Join Date
    04-10-2013
    Location
    denmark
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Printing a worksheet if a cell has a value

    Quote Originally Posted by royUK View Post
    Somethig like

    Please Login or Register  to view this content.
    I need something similar to this code. But the cells the code checks has a formular that returns a number. If that number is higher than zero it should print the sheet, if it is zero it shouldn´t. As it is now the code will print the sheet as long as there is a formular in the cell, no matter what the cell returns.

    Any suggestions?

  16. #16
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Printing a worksheet if a cell has a value

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

+ 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