+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: Macro to hide sheet based on cell value within the sheet

  1. #16
    Valued Forum Contributor
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    895

    Re: Macro to hide sheet based on cell value within the sheet

    Hi

    If you use this version of code
    Private Sub Workbook_Open()
    Dim ws As Worksheet
    For Each ws In Worksheets
    
    If ws.Range("C2") <> Date Then
    ws.Visible = False
    End If
    
    Next ws
    End Sub
    and any of C2 (in each worksheet) is not equal to present day (date) then will be the error because macro cannot hide all sheets in workbook. (try to hide by hand all sheets in workbook)
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  2. #17
    Registered User
    Join Date
    12-08-2011
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Macro to hide sheet based on cell value within the sheet

    Thanks again! I don't know what's happened. I have a "Summary" tab where the formula in C2 is "=today()", so that tab should always be visible (I would think). It's working again now. However, I was wondering if you had any ideas on how I could show tabs based on a rolling date. For example, I'd want to show today's tab and all the tabs for the next 7 days. Then tomorrow, I'd like today's tab to go away and show the next 7 days worth of tabs. I thought I could do this by adding more logic like <> Date + 1, <> Date + 2, etc, but that didn't work. Any suggestions?

    Thank you so much!

  3. #18
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Macro to hide sheet based on cell value within the sheet

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  4. #19
    Registered User
    Join Date
    12-08-2011
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Macro to hide sheet based on cell value within the sheet

    Quote Originally Posted by tom1977 View Post
    Hi

    If you use this version of code
    Private Sub Workbook_Open()
    Dim ws As Worksheet
    For Each ws In Worksheets
    
    If ws.Range("C2") <> Date Then
    ws.Visible = False
    End If
    
    Next ws
    End Sub
    and any of C2 (in each worksheet) is not equal to present day (date) then will be the error because macro cannot hide all sheets in workbook. (try to hide by hand all sheets in workbook)
    Hi Tom1977,

    I was wondering if you had a chance to review the question I posed a couple of weeks ago. What I'm need to accomplish is to show tabs for a rolling 7 day period, meaning not just today's but also all tabs for the next week, while hiding the tabs for yesterday and previous. Do you know how I could accomplish this by modifying the code you've already been so kind to provide?

    Thanks!

+ 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.2.0