Hide/Unide Pages - Macro Pls Help

scoscione

New Member
Joined
Feb 24, 2016
Messages
10
Hello all,

I have a file with multiple pages and which will have two different type of users:
1. the one updating the drivers behind the calculations (mappings sheets)
2. the ones using the final information ( pivot and chart sheets)

I am trying to segment the file so that if there is a reading user (number 2) he will see only the pivot and chart sheets. But if the user is a super user (number 1) he/she will qlik on a button and input a passoword to show the drivers sheets. Once he/she is done, he/she will qlik the other button to hide the drivers sheets.

The objective is to reduce the number of information diplayed to users (I had users deleting mapping sheets and thus generating issues with the file) and thus making it easier to read.

So far I was only able to do this (with the help of the forum previous questions). The issue is this one just leaves the index (welcome sheet) displayed, and I need to have index, sheet 1 and sheet 2 displayed. After that I want to add a button that enables the user to see the drivers if needed.

Code:
Private Sub Workbook_Open()Dim wsSheet As Worksheet
Application.ScreenUpdating = False
    For Each wsSheet In Worksheets
    If wsSheet.Name = "Index" Then
    Else
    wsSheet.Visible = False
    End If
    Next wsSheet
Application.ScreenUpdating = True
End Sub

I am not good at macros :( and I am getting very confused so I would really appreciate any help :)

Thanks.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
With hiding sheets, you need to have at least one sheet visible. A "Select Case" statement would be an easy way to make changes based off of sheet name. Here's more info on Select Case: Select Case Statement in Excel VBA Macro Code. Alternative to Multiple If, Or, And Else Statements

Code:
Private Sub Workbook_Open()
Dim ws As Worksheet


With Application
    .ScreenUpdating = False
    Sheets("Sheet1").Visible = xlSheetVisible
    
    For Each ws In Worksheets
        Select Case ws.Name
            Case "Index", "Sheet1", "Sheet2"
                ws.Visible = xlSheetVisible
            Case Else
                ws.Visible = xlSheetVeryHidden
        End Select
    Next ws
    .ScreenUpdating = True
End With
End Sub
 
Upvote 0
Thanks a lot :)
I was able to successfully implement all the macros for the groups of sheets.

In this way the user currently opens a page and it opens just the index page, and I added control buttons where the users selects which groups of sheets he would be seeing.

Regards

With hiding sheets, you need to have at least one sheet visible. A "Select Case" statement would be an easy way to make changes based off of sheet name. Here's more info on Select Case: Select Case Statement in Excel VBA Macro Code. Alternative to Multiple If, Or, And Else Statements

Code:
Private Sub Workbook_Open()
Dim ws As Worksheet


With Application
    .ScreenUpdating = False
    Sheets("Sheet1").Visible = xlSheetVisible
    
    For Each ws In Worksheets
        Select Case ws.Name
            Case "Index", "Sheet1", "Sheet2"
                ws.Visible = xlSheetVisible
            Case Else
                ws.Visible = xlSheetVeryHidden
        End Select
    Next ws
    .ScreenUpdating = True
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top