+ Reply to Thread
Results 1 to 4 of 4

Hide/Unhide sheets when a cell has a certain value

Hybrid View

  1. #1
    Registered User
    Join Date
    03-26-2012
    Location
    Hamilton, Bermuda
    MS-Off Ver
    Excel 2010
    Posts
    5

    Hide/Unhide sheets when a cell has a certain value

    Hello all,

    Please be patient with me. I am completely brand new to VBA. I have a work task that requires me to make a certain sheet hide when a certain value is chosen from a Data Validation. Can anyone give me a simple code that allows me to do this? It would be greatly appreciated.

    Many thanks,
    Magical

  2. #2
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Hide/Unhide sheets when a cell has a certain value

    Paste this in ThisWorkbook code sheet in vba and change the sheets name according to your needs:

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
        Application.EnableEvents = False
        Application.ScreenUpdating = False
        
        If Sh.Name = "SheetName" And Target.Column = 1 And Target.Row = 3 Then
            If Target.Value = 10 Then
                Sheets("HideShowSheet").Visible = False
            Else
                Sheets("HideShowSheet").Visible = True
            End If
        End If
        
        Application.ScreenUpdating = True
        Application.EnableEvents = True
    End Sub
    SheetName should be changed to the name of the sheet which contains the cell that will determine if your controlled sheet should be hidden or not.
    The 1 from Target.Column should be changed to the column number of the cell that contains the value.
    The 3 from Target.Row should be changed to the row number of the cell that contains the value.
    The 10 from Target.Value should be changed to the value that the cell should have to hide the sheet.
    HideShowSheet should change to the name of the sheet you want to hide or show according to the cell value.

    It is very important that this code is pasted on the ThisWorkbook code sheet from vba or it won't work.

    I hope that helps.
    Last edited by Pichingualas; 03-26-2012 at 03:04 PM. Reason: Changed colour of 10 cause it was hard to read
    .?*??)
    `?.???.?*??)?.?*?)
    (?.?? (?.?
    Pichingualas <---
    ??????????????????????????

    Wrap your code with CODE TAGS.
    Thank those who helped you, Don't forget to add to their REPUTATION!!! (click on the star below their post).
    Please mark your threads as [SOLVED] when they are (Thread Tools->Mark thread as Solved).

  3. #3
    Registered User
    Join Date
    03-26-2012
    Location
    Hamilton, Bermuda
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Hide/Unhide sheets when a cell has a certain value

    Thank you very much for all of your help Pichingualas!

  4. #4
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Hide/Unhide sheets when a cell has a certain value

    Glad to help

+ 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