Protect Sheet with Different User Permissions

FloatedWheat

New Member
Joined
Jul 29, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Hello,

I am working on a workbook with a lot of information and a lot of users. I have a primary worksheet that I want to lock down, say that all the data is in the range of A1:G100 of Sheet1. I want to allow only a small portion of the users, call them Group A, to edit the contents of the primary worksheet. Adding rows, deleting rows, selecting cells and changing their values, working in the worksheet like there are no protections on it. Then I want the rest of the users, call them Group B, to be able to view the sheet and sort the data. Just sorting, not editing, adding, deleting, formatting, or anything other than sorting using filters. I've been struggling to come up with the right combination of Protect Sheet settings and Allow Edit Ranges and Permissions settings. If anyone could help with this, that would be great!

Summary
Group A: Edit cells, add/delete rows, do whatever they want with the worksheet
Group B: Only sort/use filters, nothing else
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Not sure if you are familiar with VBA

While your excel file is open click on Alt+F11, a new window will open.
From the left pane double click on the sheet name where you want this permissions to take affect.
On the main pane paste this code:

VBA Code:
Private Sub Worksheet_Activate()
    Select Case Environ("username")
    'Group A
    Case "myName1", "myName2"
        ActiveSheet.Unprotect
    'Group B - aka. Anybody who is not in Group A
    Case Else
        ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
    End Select
End Sub

Change "myName1", "myName2" with the proper usernames

To know what your system recognized username is you can run this code:

VBA Code:
Sub EnvironUserName()
    MsgBox Environ("username")
End Sub
 
Upvote 0
Not sure if you are familiar with VBA

While your excel file is open click on Alt+F11, a new window will open.
From the left pane double click on the sheet name where you want this permissions to take affect.
On the main pane paste this code:

VBA Code:
Private Sub Worksheet_Activate()
    Select Case Environ("username")
    'Group A
    Case "myName1", "myName2"
        ActiveSheet.Unprotect
    'Group B - aka. Anybody who is not in Group A
    Case Else
        ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
    End Select
End Sub

Change "myName1", "myName2" with the proper usernames

To know what your system recognized username is you can run this code:

VBA Code:
Sub EnvironUserName()
    MsgBox Environ("username")
End Sub
Hello, I appreciate the reply! One problem that may be true with this solution would be that the file lives in MS Teams, and multiple people are always working in this workbook. Do you know if the solution you provided would still work?
 
Upvote 0
Hello, I appreciate the reply! One problem that may be true with this solution would be that the file lives in MS Teams, and multiple people are always working in this workbook. Do you know if the solution you provided would still work?
That would work if you upload the latest version and they download it from there.
It would not work if they work on previously locally saved files and
not work if the excel opens on Team's (web based) UI.

Also keep in mind you might want to save your file as xlsm or xlsb instead of xlsx.
 
Upvote 0

Forum statistics

Threads
1,223,932
Messages
6,175,468
Members
452,646
Latest member
tudou

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