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

[Google Sheets] Linking Data to Cell Ranges, Sheets and Another Spreadsheet

Google sheets is part of Google Workspace that organizes data in columns and rows for reporting and data analysis. In this tutorial, you will learn how to link data within tabs, between multiple tabs and from one spreadsheet to another. Before you begin To get started, go to sheets.google.com and select "blank" to open a new blank sheet. Linking Data Below are the different ways to link data in google sheets: Linking within tabs Linking between multiple tabs Linking from one spreadsheet to another Linking data within tabs 1. Click anywhere on google sheets and type anything. 2. Right-click and select Insert link. 3. Click Select a range of cells to link. 4. The "Select a data range" box will appear. 5. Select another cell within a sheet where you want to link your data. 6. Click OK . 7. Verify the cell address before you click Apply . Linking data between mul...

[Power BI] Connecting SharePoint Excel File to Power BI (Web version)

Requirement : Auto-update of Power BI report when an excel file in SharePoint is updated. Assumptions : Power BI is already installed. User has general knowledge in SharePoint and Power BI. Level : Beginner Connecting SharePoint Excel File 1. Sign into  https://powerbi.microsoft.com . 2. On the Power BI homepage, click Get data located on the lower left corner of the page.  3. You will be given options where to get the data you will use in your report. Select  Files . 4. From the displayed options, select SharePoint - Team Sites. 5. You will be asked to enter the URL to connect to. Enter the root URL of the SharePoint site where the excel file you will use is saved. 6. The list of SharePoint folders will be displayed.  7. Select the excel file from the SharePoint list. Click Connect . 8. Click Import . 9. On the homepage, click Create and select Pick a published dataset. 10. Select the file that you want to use from the list and click Create . 11. You are now ready...

Productive Laziness: Achieving More by Doing Less

This blog is created for people who use Microsoft 365 and Google Workspace at work so they can utilize these platforms to its full potential. It also aims to reach people who are new to this to help them leverage their skills in the workplace. Both services offer productivity tools that can automate repetitive tasks and processes to get things done faster with less effort and better quality. Read this blog to learn how we can be "lazy" and "productive" at the same time with the help of these applications.