+ Reply to Thread
Results 1 to 3 of 3

Hiding Sheets based on cell value, only hiding last sheet

  1. #1
    Registered User
    Join Date
    02-17-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1

    Hiding Sheets based on cell value, only hiding last sheet

    I have a question about the macro code I am trying to use that hides sheets in my workbook based on the text of a specific cells in another worksheet. The code seems to work, and I could just make several modules using the code and tweaking it, but before I do that I would like to know if I can just use one module to accomplish my goal.

    Worksheet "A" has several cells in the B151:B157 range that have data validation drop downs for selecting Yes or No. If the Yes option is selected, I want to keep that worksheet visible in the workbook. If the No option is selected, I want to hide the worksheet. Each cell goes with a different worksheet. So 151 would go with Worksheet 1, 152 with Worksheet 2, etc.

    My current code seems to only work on the final worksheet, skipping over the first worksheets and hiding only last one. Any help on how I can alter the code to make it work on all the worksheets would be appreciated.

    Sub HideSheets()
    Dim ws As Worksheet
    Dim sWord As String
    sWord = Sheets("Autofill").Range("B151").Value
    Application.ScreenUpdating = False
    For Each ws In Worksheets
    ws.Visible = True
    Next
    If sWord = "No" Then
    Sheets("Attachment A").Visible = False
    End If
    sWord = Sheets("Autofill").Range("B152").Value
    Application.ScreenUpdating = False
    For Each ws In Worksheets
    ws.Visible = True
    Next
    If sWord = "No" Then
    Sheets("Attachment B Everify").Visible = False
    End If
    sWord = Sheets("Autofill").Range("B153").Value
    Application.ScreenUpdating = False
    For Each ws In Worksheets
    ws.Visible = True
    Next
    If sWord = "No" Then
    Sheets("Attachment C Addendum Acknowle").Visible = False
    End If
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Hiding Sheets based on cell value, only hiding last sheet

    Please wrap CODE tags around code that you post, as stated in the rules. It makes it so much easier to read and copy your code accurately.

    You're looping through all your worksheets and setting them all to visible, after each conditional check / hide.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Hiding Sheets based on cell value, only hiding last sheet

    Try something like this:
    Please Login or Register  to view this content.
    Last edited by Olly; 02-17-2014 at 03:24 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Hiding row in a sheet based on cell selection in another sheet
    By akderitend in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 09-11-2013, 09:53 AM
  2. Un-Hiding and Hiding Columns based on Drop-Down Values in a Column.
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 10-30-2011, 09:24 AM
  3. Un-Hiding and Hiding Columns based on Drop-Down Values in a Column.
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2011, 06:49 AM
  4. Replies: 11
    Last Post: 09-26-2011, 11:29 AM
  5. Hiding sheets based on value in dropdown cell
    By MrSandman in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 03-27-2007, 05:13 PM

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