Thread: [Solved] How to Control Users to edit
View Single Post
 
Old 07-24-2016, 01:28 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Assuming that these are the first names of the usernames of your users, then you could employ something like the following.

Set the default state to be locked, and use password protection. Put the password in the macro where indicated and password protect the VBA project.

Save the worksheet as macro enabled, and if the users don't allow the code, they won't be able to edit anything, and they will only be able to edit any line that has the first name of their username in column A. You can modify this to suit your requirements.

Note that Excel is not a multi-user format. Only one person can have control of the workbook at a time.

Code:
Private Sub Workbook_Open()
'In the ThisWorkbook module of the workbook
Dim strName As String
Dim lngLast As Long, i As Integer
Const strPassword As String = "password" 'Your password
    lngLast = Cells(Rows.Count, "A").End(xlUp).Row
    strName = Trim(Split(Environ("UserName"), Chr(32))(0))
    ActiveSheet.Unprotect Password:=strPassword
    For i = 2 To lngLast
        If Not Cells(i, 1) = strName Then
            Rows(i).Locked = True
            'Rows(i).Hidden = True
        Else
            Rows(i).Locked = False
            'Rows(i).Hidden = False
        End If
    Next i
    ActiveSheet.Protect Password:=strPassword
lbl_Exit:
    Exit Sub
End Sub
Damn. I hadn't seen the moderator's comment before posting
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote