+ Reply to Thread
Results 1 to 6 of 6

Hide Unhide specific sheets with cell value

Hybrid View

  1. #1
    Registered User
    Join Date
    05-01-2009
    Location
    Nashville, TN
    MS-Off Ver
    2010
    Posts
    3

    Hide Unhide specific sheets with cell value

    Hello, I am trying to hide/unhide sheets based on whether or not there is text in specific cells. I can get the first command to work, but cannot get the remaining statements to execute. Here is a sample of the first 3 [out of 40 statements] from my code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Target, Range("A13")) Is Nothing Then
        If IsEmpty(Range("A13")) Then
            Sheets("BOM DTX 1").Visible = xlSheetHidden
        Else
            Sheets("BOM DTX 1").Visible = xlSheetVisible
        End If
    End Sub
    
    Private Sub Worksheet_Change1(ByVal Target As Range)
    If Not Application.Intersect(Target, Range("A25")) Is Nothing Then
        If IsEmpty(Range("A25")) Then
            Sheets("BOM DTX 2").Visible = xlSheetHidden
        Else
            Sheets("BOM DTX 2").Visible = xlSheetVisible
        End If
    End If
    End Sub
    
    
    Private Sub Worksheet_Change2(ByVal Target As Range)
    If Not Application.Intersect(Target, Range("A36")) Is Nothing Then
        If IsEmpty(Range("A36")) Then
            Sheets("BOM DTX 3").Visible = xlSheetHidden
        Else
            Sheets("BOM DTX 3").Visible = xlSheetVisible
        End If
    End If
    End Sub
    Thank you,
    Aaron

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,318

    Re: Hide Unhide specific sheets with cell value

    I think you may have more success with just one change sub and using a Select Case statement...

  3. #3
    Registered User
    Join Date
    05-01-2009
    Location
    Nashville, TN
    MS-Off Ver
    2010
    Posts
    3

    Re: Hide Unhide specific sheets with cell value

    Thank you for the reply. I am a novice at VBA. Am I on the right track here? And if so, how do I get it to continue to the next hide/unhide based on contents of next cell/range in the same sheet?
    Sub Hide-Unhide()
    Select Case Range("A13")
         Case Is = Empty
            Sheets ("BOM DTX 1").Hidden = True
         Case Else <> Empty
            Sheets ("BOM DTX 1"). Hidden = False
    End Select
    End Sub
    Last edited by aksnave; 03-23-2012 at 06:12 PM. Reason: missing ')'

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,318

    Re: Hide Unhide specific sheets with cell value

    Select case may not be the best way. Try adapting this...
    Private Sub Worksheet_Change(ByVal Target As Range)
        Sheets("BOM DTX 1").Visible = IsEmpty(Range("A13"))
        Sheets("BOM DTX 2").Visible = IsEmpty(Range("A25"))
        Sheets("BOM DTX 3").Visible = IsEmpty(Range("A36"))
    End Sub

  5. #5
    Registered User
    Join Date
    05-01-2009
    Location
    Nashville, TN
    MS-Off Ver
    2010
    Posts
    3

    Re: Hide Unhide specific sheets with cell value

    Thank you dangelor...that is super clean! I adjusted it to below so the sheet is hidden if cell is empty and it works fantastic!
    Private Sub Worksheet_Change(ByVal Target As Range)
        Sheets("BOM DTX 1").Visible = Not IsEmpty(Range("A13"))
        Sheets("BOM DTX 2").Visible = Not IsEmpty(Range("A25"))
        Sheets("BOM DTX 3").Visible = Not IsEmpty(Range("A36"))
    End Sub

  6. #6
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,318

    Re: Hide Unhide specific sheets with cell value

    Glad it works for you!

+ 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.6.0 RC 1