I have a simple tracking worksheet for project costs. The data is in cells (A1:I23). I coded it so the date and time update off to the side at the bottom of the data range (J23:K24 currently). It's also set to lock those date/time cells so users can't mess with it. Everything works except when rows are inserted at bottom of range (and then those rows are late deleted) you get the generic locked sheet message, which I don't want since user s/b able to delete/insert rows at will. I already made it to AllowDeletingRows:=True, so not sure what I'm missing?
I also have my worksheet change code below so that the date/time update whenever there's a change to a cell in the relevant range:
Thanks!
James
Code:
Sub [COLOR=#0000ff]Update_Date_Time2[/COLOR]()
Dim ws As Worksheet, D, T As Range
Set ws = ThisWorkbook.Worksheets("Project Tracking")
Set D = Range("J1").Offset(Application.Match("Current as of:", Range("J:J"), 0), 0)
Set T = Range("J1").Offset(Application.Match("Current as of:", Range("J:J"), 0), 1)
If ws.ProtectContents = True Then
ws.Unprotect Password:="abc"
End If
'Set date and time. (The rows move regularly when new costs are added/deleted, so using this approach.)
D = Date
T = "@ " & Time
'Lock the wksht. Protect only the below range. DrawingObjects:=False allows the inserting/editing of objects (like a PDF file).
If ws.ProtectContents = False Then
'ws.Range(Cells.Address).Locked = False
ws.Range("$J23:$K24").Locked = True
ws.Protect Password:="abc", DrawingObjects:=False, AllowInsertingRows:=True, AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True
End If
End Sub
I also have my worksheet change code below so that the date/time update whenever there's a change to a cell in the relevant range:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)'Change Event:
'Check if the target cell (A1:i500) has been changed.
If Not Intersect(Target, Range("A1:i500")) Is Nothing Then
Call [COLOR=#0000ff]Update_Date_Time2[/COLOR]
End If
End Sub
Thanks!
James