+ Reply to Thread
Results 1 to 23 of 23

Hide Pages On Sheet Based On Value In Cell

  1. #1
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Question Hide Pages On Sheet Based On Value In Cell

    Hello, I have an interesting issue here;

    If Cell X1 on my sheet receives a 1, only Page 1 may be shown, and Page 2 and 3 hidden.
    If Cell X1 on my sheet receives a 2, only Page 1 and 2 may be shown, and Page 3 hidden.
    If Cell X1 on my sheet receives a 3, all the pages may be shown.

    What would be the best way of doing this?
    There is so much good in the worst of us,
    And so much bad in the best of us,
    That it hardly behooves any of us
    To talk about the rest of us.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Hide Pages On Sheet Based On Value In Cell

    Something like this, in the worksheet_change event should do the trick:

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Hide Pages On Sheet Based On Value In Cell

    Hmm, I can't seem to make that work, at all. Does it work for you?

  4. #4
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Hide Pages On Sheet Based On Value In Cell

    hi,
    the code provided by Andrew works fain!
    if you have x1=1, you can see Sheet1 only and so on!
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  5. #5
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Hide Pages On Sheet Based On Value In Cell

    Oh! I see what you're doing there now, that does work great! However, I'm trying to display numbers of pages, not sheets.

  6. #6
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Hide Pages On Sheet Based On Value In Cell

    of course it's not a ...method, but I would see my printarea and then something like this
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Hide Pages On Sheet Based On Value In Cell

    This... might work! Now how do I merge that code with this code already on the sheet?

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Hide Pages On Sheet Based On Value In Cell

    Here is my sample workbook. I need this code:

    Please Login or Register  to view this content.
    .. to be merged with the Worksheet_Change event already assigned to the Inspection Report. Does anyone know how?
    Attached Files Attached Files

  9. #9
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Hide Pages On Sheet Based On Value In Cell

    it depends of what you want to achieve...
    just try
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Hide Pages On Sheet Based On Value In Cell

    Hmm, that almost does it, but it's really slow, especially when I scroll down past the bottom of the last page. All the numbered column cells get really wide too. Any more ideas?

  11. #11
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Hide Pages On Sheet Based On Value In Cell

    nope, I am sorry!

  12. #12
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Hide Pages On Sheet Based On Value In Cell

    Anyone else have any ideas here? If I could just set the print area according to the X1 value, that would work as well; might be easier than trying to hide entire pages.

  13. #13
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Hide Pages On Sheet Based On Value In Cell

    swordswinger710,

    Attached is a modified version of your posted workbook. I made several code changes, most notably to the "Save Documentation as PDF" button which is where the .PageSetup.PrintArea code was incorporated (great idea on that, john55!).

    Take a look and test it out. Let me know if that works for you.
    Attached Files Attached Files
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  14. #14
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Hide Pages On Sheet Based On Value In Cell

    Whoa, I think this is gonna do it! Thank you tigeravatar! How do I get the Inspection Report Attachment to do the same?

  15. #15
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Hide Pages On Sheet Based On Value In Cell

    swordswinger710,

    It already does. If it was not printed, then the condition to print it was not met. Here's the snippet of code to see if it should be printed:
    Please Login or Register  to view this content.


    And later in the macro, here's the snippet for the 'Inspection Report Attachment' print area:
    Please Login or Register  to view this content.


    In the file you posted, there is no information in 'Inspection Report Attachment' cell B6, so it was not included in the SaveAsPDF.

  16. #16
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Hide Pages On Sheet Based On Value In Cell

    Although, now that I've said that, I noticed that the bIRA variable was never declared or set, oops, lol. Here's a corrected version of the code:
    Please Login or Register  to view this content.

  17. #17
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Hide Pages On Sheet Based On Value In Cell

    And that does it! YEEEHAAAAA!! Sorry.

    Any idea why it's asking me to save when I haven't done any changes though?

  18. #18
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Hide Pages On Sheet Based On Value In Cell

    Oh, and am I wrong, or would we be able to get rid of the PrintArea stuff here now and just go with the "R1" value?
    Please Login or Register  to view this content.

  19. #19
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Hide Pages On Sheet Based On Value In Cell

    The R1 value is simply 1, 2, or 3. You need to tell the page the specific range of cells that will be used for the print area. That specific range is based on R1, but the R1 value isn't "A1:R46", it's 1. That's why it's setup like that.

  20. #20
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Hide Pages On Sheet Based On Value In Cell

    As far as prompting to save, your workbook has a lot going on in open events and sheet_change events. Even if you don't make any changes to the workbook, simply the act of opening it is causing the workbook to be flagged as "dirty" (meaning it thinks it needs to be saved). There's not really a way around that with your current setup.

  21. #21
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Hide Pages On Sheet Based On Value In Cell

    Awesome - would there be a way to have it automatically save upon opening then? So that if the user closed the workbook immediately after doing so, that prompt wouldn't appear?

  22. #22
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Hide Pages On Sheet Based On Value In Cell

    You could try adding the line ThisWorkbook.Save as the last line in the workbook_open event.

  23. #23
    Forum Contributor swordswinger710's Avatar
    Join Date
    02-20-2008
    Location
    Bright, Canada
    MS-Off Ver
    2010
    Posts
    845

    Re: Hide Pages On Sheet Based On Value In Cell

    Ha! You got it! This problem is now OVER! Thank you a MILLION for all you've helped me with!

+ 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