Consulting

Results 1 to 6 of 6

Thread: How to unhide Sheets based on 3 cell values

  1. #1

    How to unhide Sheets based on 3 cell values

    E.g.
    I'm in worksheet "Main" (all other sheets are hidden), in Cell A1 I type "SHEET 1", in A2 I type "SHEET 2" and in A3 I type "SHEET 3". How can I unhide SHEET 1, SHEET 2 en SHEET 3 with a command button (in VBA)? Of course if in A1 is typed "SHEET 4" then SHEET 4 must be unhidden.

    So the value that is put in in cell A1, A2 en A3 must be used to open the corresponding Worksheets.

    Hope someone can help me, I've searched for hours couldn't find the wright answer. Thank you!

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum!
    Private Sub CommandButton1_Click()    
        Dim c As Range
        On Error Resume Next
        For Each c In Range("A1", Cells(Rows.Count, "A").End(xlUp))
            Worksheets(c.Value).Visible = xlSheetVisible
        Next c
    End Sub

  3. #3
    Thanks very much!

  4. #4
    But what if SHEET 1 is already vissible and SHEET 1 is not filled in in A1 to A999? Is it possible to hide SHEET 1? So na matter what, when you push the button ONLY the sheets mentioned in A1 to A999 must be visible, all others invisible. Is that possible?

  5. #5
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    You could hide them all except the current worksheet first:

    Sub pk1()
        Dim ws As Worksheet, c As Range
        For Each ws In ThisWorkbook.Worksheets
            If ws.Name <> ThisWorkbook.ActiveSheet.Name Then
                ws.Visible = xlSheetHidden
            End If
        Next ws
        On Error Resume Next
        For Each c In Range("A1", Cells(Rows.Count, "A").End(xlUp))
            Worksheets(c.Value).Visible = xlSheetVisible
        Next c
    End Sub
    Semper in excretia sumus; solum profundum variat.

  6. #6
    Thanks again! Next time I'm not going to search the internet for hours!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •