User Access Visibility

SteynBS

Board Regular
Joined
Jun 27, 2022
Messages
111
Office Version
  1. 365
Platform
  1. Windows
Good day

I was wondering it is possible to restrict the visible cells to the person currently using the file. If user A opens the file, he can only see the data where his name is assigned in a row. If user B opens the file he can only see data assigned to him.

This is a file in one drive where multiple users has access to it, but we need to restrict what they can see.
 
This will keep Header row:
VBA Code:
Option Explicit

Private Sub Workbook_Open()
Dim sht As Worksheet, nRange As Range, cell As Range, un As String, n As Range, i As Long
'Set the UserName to search for
un = Application.UserName
'Define the Sheet that you want to search for Names in
Set sht = ThisWorkbook.Sheets("Sheet1")
'Unprotect the Worksheet and unlock cells
sht.Unprotect ("pword")
sht.Cells.Locked = False
'Define the Column to search for Name. This searches Column A
Set nRange = sht.Range(Cells(2, 1), Cells(sht.UsedRange.Rows.Count, 1))
'Check each row in Column A for Name match and hide and lock rows that don't match
For Each cell In nRange
    Set n = cell.Find(un, LookAt:=xlPart)
    If n Is Nothing Then
        sht.Rows(cell.Row).Hidden = xlVeryHidden
        sht.Rows(cell.Row).Locked = True
    End If
Next cell
sht.EnableSelection = xlUnlockedCells
sht.Protect ("pword")
End Sub
Thank you this works - sorry just need to make sure if there is a way to still use the sort function on the filtered data?
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,224,814
Messages
6,181,128
Members
453,021
Latest member
Justyna P

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