Hi
I have problems with writing a VBA for a shared workbook. I want to set up a shared workbook with the following function.
1) allow users to edit column D, Column A-C tracks the edit Date, time, username
2) Lock cells in column D after the first edit
3) Lock cells Column A-C to prevent users from changing it
The below is the working VBA code for tracking the date/time/username based on data keyed into column D.
But since protect and deprotect doesn't work on a shared workbook. I just use the normal "Protect Sheet" function and put it in a local shared folder instead of using the "Share Workbook" function. There's a problem: if a user doesn't hit the "Enable Content" button when they first open the workbook, the code doesn't work - meaning they can type in column D but Column A-C doesn't record the Date, time and username. Need some help with this. Thanks
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range, B As Range, Inte As Range, r As Range
Set A = Range("D:D")
Set Inte = Intersect(A, Target)
If Inte Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each r In Inte
If r.Value > 0 Then
ActiveSheet.Unprotect
ActiveSheet.Unprotect
r.Offset(0, -3).Value = Date
r.Offset(0, -3).NumberFormat = "dd-mm-yyyy"
r.Offset(0, -2).Value = Time
r.Offset(0, -2).NumberFormat = "hh:mm:ss AM/PM"
r.Offset(0, -1).Value = Application.UserName
Target.Locked = True
ActiveSheet.Protect
Else
End If
Next r
Application.EnableEvents = True
End Sub
I have problems with writing a VBA for a shared workbook. I want to set up a shared workbook with the following function.
1) allow users to edit column D, Column A-C tracks the edit Date, time, username
2) Lock cells in column D after the first edit
3) Lock cells Column A-C to prevent users from changing it
The below is the working VBA code for tracking the date/time/username based on data keyed into column D.
But since protect and deprotect doesn't work on a shared workbook. I just use the normal "Protect Sheet" function and put it in a local shared folder instead of using the "Share Workbook" function. There's a problem: if a user doesn't hit the "Enable Content" button when they first open the workbook, the code doesn't work - meaning they can type in column D but Column A-C doesn't record the Date, time and username. Need some help with this. Thanks
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range, B As Range, Inte As Range, r As Range
Set A = Range("D:D")
Set Inte = Intersect(A, Target)
If Inte Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each r In Inte
If r.Value > 0 Then
ActiveSheet.Unprotect
ActiveSheet.Unprotect
r.Offset(0, -3).Value = Date
r.Offset(0, -3).NumberFormat = "dd-mm-yyyy"
r.Offset(0, -2).Value = Time
r.Offset(0, -2).NumberFormat = "hh:mm:ss AM/PM"
r.Offset(0, -1).Value = Application.UserName
Target.Locked = True
ActiveSheet.Protect
Else
End If
Next r
Application.EnableEvents = True
End Sub