+ Reply to Thread
Results 1 to 2 of 2

Checkbox When Unchecked Hides Worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    12-06-2012
    Location
    aberdeen
    MS-Off Ver
    Excel 2003
    Posts
    1

    Checkbox When Unchecked Hides Worksheet

    Hi,

    What I would like to do is have a list of checkboxes that when they are unchecked hide the worksheets of the same name, and when checked unhide them.

    For example have a title worksheet containing seven checkboxes each relating to a day of the week. There are also a further seven worksheets each named a day of the week.

    When the ‘Tuesday’ checkbox is unchecked on the title worksheet, the ‘Tuesday’ worksheet is hidden.

    Can anyone offer any advise if this is possible?

    Doug.

  2. #2
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Checkbox When Unchecked Hides Worksheet

    Try the attached example. When you create the listbox on the worksheet, it should
    have MultiSelect option = 1 and ListStyle = 1.
    You should find, in the attached file, that the five worksheets named "Monday" through "Friday" start out
    visible, and are hidden when you uncheck each day-name in the list box.

    Here is the code. In the worksheet module, and I used "Sheet1" for this:
    Private Sub ListBox1_Change()
        
        If flag Then Exit Sub
        
        Sheets(ListBox1.List(ListBox1.ListIndex)).Visible = _
            ListBox1.Selected(ListBox1.ListIndex)
        
    End Sub
    then create a new module and add this code:
    Public flag As Boolean
    
    Private Sub Auto_Open()
    Dim j As Integer
    
        With Sheets("Sheet1")
            .ListBox1.AddItem "Monday"
            .ListBox1.AddItem "Tuesday"
            .ListBox1.AddItem "Wednesday"
            .ListBox1.AddItem "Thursday"
            .ListBox1.AddItem "Friday"
        
            flag = True
            For j = 0 To .ListBox1.ListCount - 1
                Sheets(.ListBox1.List(j)).Visible = True
                .ListBox1.Selected(j) = True
            Next
            flag = False
            
        End With
        
    End Sub
    Attached Files Attached Files

+ 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