Skip to main content

[Excel] How to Protect Multiple Excel Tabs with Different Passwords


Requirement: 
I have an excel file with multiple tabs which is being updated monthly by many users. I want to create a password for each tab so that each user can only view and edit their own tab.

Limitation: Protect Sheet Function in Excel is notoriously weak. 

Solution: Use VBA code to set up password on each tab.

Protecting Multiple Tabs with Different Passwords

Let's say I have three teams which need to report their daily sales in one excel spreadsheet. The three teams are named Team Apple, Team Watermelon and Team Grapes. First, let's create a new tab for each one of them.

1. Add three new tabs and rename each according to the team name.


2. Create a column for 'Name', 'Item', 'Sales' and 'Date' for each team. 


3. Click Visual Basic from the 'Developer' tab.



4. From Sheet 2 to Sheet 4, copy and paste the VBA code below:


VBA Code:

Private Sub Worksheet_Activate()
    Dim strPassword As String
    'On Error Resume Next
    
    Me.Unprotect Password:="Apple"
    Me.Columns.Hidden = True
    Me.Protect Password:="Apple"
    
    strPassword = InputBox("Enter password to access DATA sheet")
    
    If strPassword = "" Then
        ActiveSheet.Visible = False
        Worksheets("Sheet1").Select
        Exit Sub
    ElseIf strPassword <> "Apple" Then
        MsgBox "Password Incorrect "
        ActiveSheet.Visible = False
        Worksheets("Sheet1").Select
        Exit Sub
    Else
        Me.Unprotect Password:="Apple"
        Me.Columns.Hidden = False
    End If
    Range("A1").Select
    On Error GoTo 0
End Sub

Private Sub Worksheet_Deactivate()
    'On Error Resume Next
    Me.Unprotect Password:="Apple"
    Me.Columns.Hidden = True
    Me.Protect Password:="Apple"
    On Error GoTo 0
End Sub

5. Change the password for each sheet as highlighted in yellow text background above. In this example, the name of the team per tab is used as the password. Once you complete changing the password for each sheet, close the Visual Basic Application.

6. When you try to click on any protected sheet, it will now ask for a password. Enter the correct password assigned per tab to view and edit.


7. When you enter an incorrect password, it will display an error and the excel tab will be automatically hidden. To open it, you need to right-click on any open tab and unhide the sheet.


Comments

Post a Comment

Popular posts from this blog

[Microsoft Flow] How to Connect Microsoft Form Responses to Power BI

Requirement : Auto-import of data to Power BI when a new response in Microsoft Forms is submitted. Solution : Connect Microsoft Forms to Power BI through Microsoft Flow. Assumptions : Power BI is already installed. Microsoft Form is already created. Creating a Streaming Dataset 1. Sign into https://powerbi.microsoft.com. 2. On the Power BI homepage, click New under 'My workspace'.  3. Select Streaming dataset . 4. Select API and click Next . 5. Enter a name for your dataset. 6. Enter each question from MS Forms to 'Values from stream' in Power BI and select the type of the answer for each. 7. Click Create . 8. Turn on Historic data analysis and click Done . 9. When you click the name of your dataset under 'My workspace', you are now ready to create a Power BI report. Connecting MS Forms to Power BI 1. Log into https://flow.microsoft.com. 2. Click My flows in the left navigation bar. 3. Click New flow and select Automated cloud flow . 4. Before you create yo...

[SharePoint] Creating a List

SharePoint List provides flexible ways to store and display information in the form of a list similar to a database or spreadsheet. Assumptions : User has Full Control/Modify Access in SharePoint Intended Audience :  Someone new to SharePoint Online Level :  Beginner Creating a SharePoint List 1. In your SharePoint homepage, click the settings icon located on the upper right corner of the page. 2. Click Add a page . 3. From the list of SharePoint apps, select Custom List. 4. Enter a name for your list. Click Create . 5. You will see your new list in the gallery. 6. When you click the list, you will be redirected to the list page where you can edit the list settings. Creating a Column in a SharePoint List 1. You can directly create a column in your list by clicking the Add Column option.  2. Select your preferred column types from the list. 3. Enter the Name and Description of the column and click Save . 4. You can also create a column from the list settings.