+ Reply to Thread
Results 1 to 7 of 7

VBA to UnHide/Hide Sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    06-12-2013
    Location
    Fairbury NE
    MS-Off Ver
    Excel 2007
    Posts
    70

    VBA to UnHide/Hide Sheets

    I have a workbook with about 20 worksheets in it.
    6 are visible
    3 are hidden
    the remaining are very hidden

    I'm creating a "welcome" page to the workbook with instructions on how to update data. The data between the 20 sheets consists of pivot tables, charts and summary data. The Visible sheets are data for management's review (all protected). The 3 hidden sheets are pivot tables that the user needs to pull data from and the very hidden sheets are not to be seen by anyone.

    In my "welcome" page, I added the instructions of how to update data, but wanted an area where I could assign a checkbox or button to click on for the user to unhide my 3 hidden sheets (say Sheet1, Sheet2 and Sheet3). I do not want it to unhide my very hidden sheets. Then, when the information needed is retrieved from those sheets, I would like the user to use a checkbox or button to hide the 3 hidden sheets again. Is there a way to do this?

    I tried creating custom view but couldn't do that because of the pivot tables (the option was disabled). I'm a beginner in VBA so don't even know how to begin. Hoping someone can help.
    Last edited by maryren; 02-20-2014 at 05:01 PM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: VBA to UnHide/Hide Sheets

    Hi maryren,

    If you can work with some code, take the following and adapt it to your requirements. I created a userform that unhides the days of the week by means of checkboxes. Hiding and unhiding sheets all use the same principles in VBA so you should be able to adapt my code without any issues. If you're not comfortable with coding VBA then you'll need to upload your workbook. Anyways, my code from my userform:
    Private Sub CommandButton1_Click()
        Dim shtNm(5) As Worksheet
        Dim x As Long
        Application.ScreenUpdating = False
        For x = 1 To 5
            Select Case x
                Case 1
                    Set shtNm(x) = Worksheets("Monday")
                    If Me.Controls("cb" & x).Value = True Then
                        shtNm(x).Visible = xlSheetVisible
                    End If
                Case 2
                    Set shtNm(x) = Worksheets("Tuesday")
                    If Me.Controls("cb" & x).Value = True Then
                        shtNm(x).Visible = xlSheetVisible
                    End If
                Case 3
                    Set shtNm(x) = Worksheets("Wednesday")
                    If Me.Controls("cb" & x).Value = True Then
                        shtNm(x).Visible = xlSheetVisible
                    End If
                Case 4
                    Set shtNm(x) = Worksheets("Thursday")
                    If Me.Controls("cb" & x).Value = True Then
                        shtNm(x).Visible = xlSheetVisible
                    End If
                Case 5
                    Set shtNm(x) = Worksheets("Friday")
                    If Me.Controls("cb" & x).Value = True Then
                        shtNm(x).Visible = xlSheetVisible
                    End If
            End Select
        Next x
        Application.ScreenUpdating = True
        Unload Me
    End Sub
    Let me know if this helps you or only confuses you.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    06-12-2013
    Location
    Fairbury NE
    MS-Off Ver
    Excel 2007
    Posts
    70

    Re: VBA to UnHide/Hide Sheets

    Hi Mordred,

    I can't send the file since it is confidential, but I have attached a sample file. I wanted to keep the checkbox on the welcome page if possible instead of creating a userform, is that possible? I'm not very good with VBA, so don't think tweaking your example will do much good for me.

    Thanks for all your help
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    10-01-2013
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    136

    Re: VBA to UnHide/Hide Sheets

    The code attached should be able to help you hide and unhide sheets when the checkbox in Sheet5 is clicked. Proceed and Modify the code to your needs.

    Private Sub CheckBox1_Click()
          If Range("E4").Value = True Then
            Sheets("Sheet1").Select
            ActiveWindow.SelectedSheets.Visible = False
            Sheets("Sheet2").Select
            ActiveWindow.SelectedSheets.Visible = False
            Sheets("Sheet3").Select
            ActiveWindow.SelectedSheets.Visible = False
            Sheets("Sheet5").Select
        Else
            Sheets("Sheet1").Visible = True
            Sheets("Sheet1").Select
            Sheets("Sheet2").Visible = True
            Sheets("Sheet2").Select
            Sheets("Sheet3").Visible = True
            Sheets("Sheet5").Select
        End If
      
    End Sub
    Don't forget to mark the thread as solved if this solved your problem and don't forget to click on the Star
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-12-2013
    Location
    Fairbury NE
    MS-Off Ver
    Excel 2007
    Posts
    70

    Re: VBA to UnHide/Hide Sheets

    WOW! This is great and exactly what I was trying to do! Thanks so much.

  6. #6
    Forum Contributor
    Join Date
    10-01-2013
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    136

    Re: VBA to UnHide/Hide Sheets

    I have solved it also using your example file. Just proceed and click on the checkbox and your desires will be met.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    10-01-2013
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    136

    Re: VBA to UnHide/Hide Sheets

    Thanks for the Rep!
    Last edited by vnzerem; 02-20-2014 at 05:09 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. Hide/Unhide sheets
    By mnewdick in forum Excel General
    Replies: 4
    Last Post: 07-19-2013, 10:11 AM
  2. Hide & Unhide sheets
    By Zorro9758 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-05-2013, 04:41 PM
  3. [SOLVED] hide unhide all sheets except for the active one
    By Bishonen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-24-2012, 09:41 AM
  4. [SOLVED] Hide or unhide sheets
    By Jakes in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2012, 02:09 AM
  5. Hide/Unhide Sheets
    By Runner77 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-16-2006, 05:25 AM

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